Hi All,
i would need an help in the program i'm developing.
I have an ea that open a position, buy, with a specified magic index (example id:111)
After some pips if it is triggered the strategy, it opens a new position always buy and always id:111... and so on anytime the strategy is triggered.
Anytime a new position is opened i would need to recalculate for all the buy position with id:111 the take profit, made by this formula : (OpenPriceOrder1*Lotsize1+OpenpriceOrder2*Lotsize2+...+OpenpriceOrderX*LotSizeX)/(Lotsize1+Lotsize2+....+LotsizeX)
Thank you to all will help me!!!!!
example,
//+------------------------------------------------------------------+ //| HaskayafxTakeProfitEAV01.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict input int MagicNumber=1111; double TakeProfirLevel=0.0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- TakeProfitUtil(MagicNumber); TakeProfitUpdate(MagicNumber,TakeProfirLevel); } //+------------------------------------------------------------------+ int TakeProfitUtil(int GlnMagicNumber) { int total = OrdersTotal(); TakeProfirLevel=0.0; bool tck; for(int i=total-1;i>=0;i--) { tck= OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; if(OrderMagicNumber()==GlnMagicNumber) { TakeProfirLevel=TakeProfirLevel+(OrderOpenPrice()*OrderLots()); } } return(0); } int TakeProfitUpdate(int GlnMagicNumber,double TPlevel) { int total = OrdersTotal(); TakeProfirLevel=0.0; bool tck; double TP=0; for(int i=total-1;i>=0;i--) { tck= OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; double Dj=MarketInfo(OrderSymbol(),MODE_DIGITS); TP=NormalizeDouble(TPlevel,Dj); if(OrderMagicNumber()==GlnMagicNumber) tck=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TP,0,CLR_NONE); } return(0); }
example,
It works! Really wonderfull! Just a last help if you can :
The formula TakeProfirLevel=TakeProfirLevel+(OrderOpenPrice()*OrderLots()); should be implemented before update the take profits dividing the TotalOpenLots for the MagicIndex considered :-) I don't know how to calculate the TotalOpenLots...
If you could implement it and let me see where update the mql i have finished! Thanks
It works! Really wonderfull! Just a last help if you can :
The formula TakeProfirLevel=TakeProfirLevel+(OrderOpenPrice()*OrderLots()); should be implemented before update the take profits dividing the TotalOpenLots for the MagicIndex considered :-) I don't know how to calculate the TotalOpenLots...
If you could implement it and let me see where update the mql i have finished! Thanks
ok.
//+------------------------------------------------------------------+ //| HaskayafxTakeProfitEAV01.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict input int MagicNumber=1111; double TakeProfirLevel=0.0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- TakeProfitUtil(MagicNumber); TakeProfitUpdate(MagicNumber,TakeProfirLevel); } //+------------------------------------------------------------------+ int TakeProfitUtil(int GlnMagicNumber) { int total = OrdersTotal(); TakeProfirLevel=0.0; double TotalLots=0.0; bool tck; for(int i=total-1;i>=0;i--) { tck= OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; if(OrderMagicNumber()==GlnMagicNumber) { TakeProfirLevel=TakeProfirLevel+(OrderOpenPrice()*OrderLots()); TotalLots=TotalLots+OrderLots(); } } TakeProfirLevel=NormalizeDouble((TakeProfirLevel/TotalLots),Digits); return(0); } int TakeProfitUpdate(int GlnMagicNumber,double TPlevel) { int total = OrdersTotal(); TakeProfirLevel=0.0; bool tck; double TP=0; for(int i=total-1;i>=0;i--) { tck= OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; double Dj=MarketInfo(OrderSymbol(),MODE_DIGITS); TP=NormalizeDouble(TPlevel,Dj); if(OrderMagicNumber()==GlnMagicNumber) tck=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TP,0,CLR_NONE); } return(0); }
ok.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
i would need an help in the program i'm developing.
I have an ea that open a position, buy, with a specified magic index (example id:111)
After some pips if it is triggered the strategy, it opens a new position always buy and always id:111... and so on anytime the strategy is triggered.
Anytime a new position is opened i would need to recalculate for all the buy position with id:111 the take profit, made by this formula : (OpenPriceOrder1*Lotsize1+OpenpriceOrder2*Lotsize2+...+OpenpriceOrderX*LotSizeX)/(Lotsize1+Lotsize2+....+LotsizeX)
Thank you to all will help me!!!!!