Ja sam spakovao gubitke na zlato ihihihi. Tako da ne trgujem do sledece nedelje a mozda i narednog meseca. Ali to nije tema. Tema je BreakEven interna funkcija/modul, koji sam resio da vam pokaze. Sad oni koji su programeri sa poodmaklim stazom za njih to i nije nesto znacajno, ali ako ste pocetnik bogami preuzmite ovaj primer.
Ako pokusavate da b.e. nadjete bilo gde na internetu bilo bi dobro da i meni javite. Ja sam breakeven trazio i trazio, trazio reko da se ne mucim. Ma jok nema i nema. U svakom slucaju da bih vam pokazao kako "zatvori sa nulom", radi. Iskuckao sam mali price action EA koji je potpuno operativan.
Ne pokusavajte da pravite lovu sa ovim robotom jer to sigurno nece da se desi. Osnovna svrha je da vidite kako breakeven radi poso i iskoristite ga u nekom vasem projektu.
Primer kada je otvoren buy nalog i kada breakeven nije aktiviran:
[You must be registered and logged in to see this image.]
Primer kada je breakeven aktiviran :
[You must be registered and logged in to see this image.]
Najprostije receno, kada je b.e. aktivan pocvreni linija od naloga koja je do tada bila zelene boje. Sto znaci da je b.e. povukao stop loss.
Preuzmite kompletan EA:
- break_even.mq5:
- Code:
//+--------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| break_even.mq5 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| [You must be registered and logged in to see this link.] |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "drenjanind@mail.ru"
#property version "1.00"
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include<Trade\Trade.mqh>
CTrade trade;
double stop_loss = 350;
double take_profit = 20;
ulong magic_number = 5456;
double break_even= 1 ;
ENUM_ORDER_TYPE_FILLING order_type_filling = ORDER_FILLING_RETURN;
double PRC;
double STL;
double TKP;
bool open_position;
bool pending_order;
bool b_e_activ;
MqlTick last_tick;
MqlRates rates[];
double Balance= AccountInfoDouble(ACCOUNT_BALANCE);
double Equity = AccountInfoDouble(ACCOUNT_EQUITY);
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);
double DynamicPositionSize = NormalizeDouble((Equity/1000000),2);
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
ArraySetAsSeries(rates,true);
trade.SetTypeFilling(order_type_filling);
trade.SetExpertMagicNumber(magic_number);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
//----
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(SymbolInfoTick(Symbol(), last_tick))
{
Print(last_tick.time,": Bid = ",last_tick.bid," Ask = ",last_tick.ask," Volume = ",last_tick.volume);
}
else
{
Print("Error to get price informations: ", GetLastError());
}
if(CopyRates(_Symbol, _Period, 0, 20, rates)<0)
{
Print("Error copying price data ",GetLastError());
}
else
{
Print("Copied ",ArraySize(rates)," bars");
}
open_position = false;
for(int i = PositionsTotal() - 1; i > 0; i --)
{
string symbol = PositionGetSymbol(i);
ulong magic = PositionGetInteger(POSITION_MAGIC);
if(symbol == _Symbol && magic == magic_number)
{
open_position = true;
break;
}
}
if(!open_position)
{
b_e_activ = false;
}
if(open_position && !b_e_activ)
{
BreakEven(last_tick.last);
}
//-------------------------------------------------------+
bool UpTrend = rates[0].high > rates[2].high && rates[3].high < rates[5].high && rates[0].close > rates[1].close && rates[1].close > rates[2].close;
bool DownTrend = rates[0].low < rates[2].low && rates[3].low < rates[5].low && rates[0].close < rates[1].close && rates[1].close < rates[2].close;
if( UpTrend && !open_position)
{
PRC =(last_tick.ask);
STL =(PRC - stop_loss * _Point);
TKP =(PRC + take_profit * _Point);
trade.Buy( DynamicPositionSize ,_Symbol, PRC, STL, TKP, "");
}
if( DownTrend && !open_position)
{
PRC = (last_tick.bid);
STL = (PRC + stop_loss * _Point);
TKP = (PRC - take_profit * _Point);
trade.Sell( DynamicPositionSize ,_Symbol, PRC, STL, TKP, "");
}
}
//+--------------------------------------------------------------------+
//BREAK EVEN/ZATVORI SA NULOM |
//+--------------------------------------------------------------------+
void BreakEven(double price)
{
for(int i = PositionsTotal()-1; i>=0; i--)
{
string symbol = PositionGetSymbol(i);
ulong magic = PositionGetInteger(POSITION_MAGIC);
if (symbol==_Symbol && magic == magic_number)
{
ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
double PriceEntry = PositionGetDouble(POSITION_PRICE_OPEN);
double CurrentTakeProfit = PositionGetDouble(POSITION_TP);
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
{
if ( price >= (PriceEntry + (break_even * _Point)))
{
if (trade.PositionModify(PositionTicket, PriceEntry, CurrentTakeProfit))
{
Print("BreakEven - without fail. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
open_position= true;
}
else
{
Print("BreakEven - fail. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
}
}
}
else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
if ( price <= (PriceEntry - (break_even * _Point)))
{
if (trade.PositionModify(PositionTicket, PriceEntry, CurrentTakeProfit))
{
Print("BreakEven - without fail. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
open_position= true;
}
else
{
Print("BreakEven - fail. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
}
}
}
}
}
}
//+------------------------------------------------------------------+
Takodje zaboravih da napomenem da je u pitanju MQL5 kod. Tako da je opreativan samo na mt5 platformi.
Platformu mozete preuzeti sa mql5 vebsajta preko sledeceg linka:
- [You must be registered and logged in to see this link.]
Pljusnite kod u editor,kompajlujte kod, pokrenite test, i to je to. Za sva pitanja stojim na raspolaganju. Sledece sto planiram da objavim je Trailing Stop interni modul.
I eto previse je veb sajtova o programiranuju robota, ali slabo ima nesto nase. Tako da eto, prikljucite se objavite nesto korisno za druge.
Sto se tice mog programerskog staza u mql5 programskom jeziku on je veoma mali. Mozda ima mesec dana kako sam startovao. Inace PYTHON je moj top izbor, i ima sigurno godinu i vise dana kako se bavim python-om. Programiram robote za stock trading ili bar to pokusavam hahaha.
U svakom slucaju ako znate ili bar mislite da znate jedan programski jezik vrlo lako savladavate drugi.
To je to , odoh