Comment("the OrderGetTicket Value is ",orderTicket); {
Comment() should be below the brace.
Any leads on how do i make this much more efficient and not make my strategy tester load slowly, i don't know where to start.
don't assign a variable to _Symbol just use _Symbol it is what it is there for.
don't do your position loop twice (buy and then sell) just do everything you want from the first loop, you are doubling the amount of processing.
are you calling this every tick? if so it will consume a lot of processing time,
store what you need about your positions and just check the latest tick price and then take action if required, getting all positions data every tick is a drain on processing.
You can use OnTrade() to update your positions data only when a trade event occurs.

- www.mql5.com
Any leads on how do i make this much more efficient and not make my strategy tester load slowly, i don't know where to start.
don't assign a variable to _Symbol just use _Symbol it is what it is there for.
don't do your position loop twice (buy and then sell) just do everything you want from the first loop, you are doubling the amount of processing.
are you calling this every tick? if so it will consume a lot of processing time,
store what you need about your positions and just check the latest tick price and then take action if required, getting all positions data every tick is a drain on processing.
You can use OnTrade() to update your positions data only when a trade event occurs.
Use the profiler (Editor => Debug Profiling..) - it is exactly meant for that.
The problem is that the second PositionModify() function is called on every tick because it's outside the scope of the expression (only Comment() is called when the condition is met).
for(int i=PositionsTotal()-1; i>=0; i--) { if(PositionGetTicket(i)==0) continue; if(PositionGetTicket(i)>0) { if( PositionGetString(POSITION_SYMBOL)==inpSymbol && PositionGetInteger(POSITION_MAGIC)==inpMagic ) { //ORDER TYPE MUST BE THE SAME if ((PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)) { // PRICE REACHED 1:1 MOVE SL TO BREAKEVEN if (Ask>(orderOpenPrice - orderStopLoss + orderOpenPrice) && //SINCE WE MOVE THE SL TO BREAKEVEN + ADD HALF PIP TO ACCOUNT FOR SPREAD, //MEANING THIS COULD ONLY TRIGGER IF PRICE WASN'T MODIFIED YET, //THUS PREVENTING ORDERMODIFY ERROR 1 //ORDERMODIFY ERROR 1: DOING THE SAME THING OVER & OVER AGAIN WITHOUT CHANGING ANYTHING (orderStopLoss < orderOpenPrice)) { trade.PositionModify( orderTicket //CHOOSE THE CORRECT TICKET ,(orderOpenPrice + (Ask-Bid)) // SL HAS BEEN CHANGED ,orderTakeProfit); // TAKE PROFIT NOT CHANGED, ONLY THE STOPLOSS Print("the OrderGetTicket Value is ",orderTicket); } } //ORDER TYPE MUST BE THE SAME if ((PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)) { // PRICE REACHED 1:1 MOVE SL TO BREAKEVEN if (Bid < (((orderStopLoss - orderOpenPrice)- orderOpenPrice)*(-1)) //SINCE WE MOVE THE SL TO BREAKEVEN + ADD HALF PIP TO ACCOUNT FOR SPREAD, //MEANING THIS COULD ONLY TRIGGER IF PRICE WASN'T MODIFIED YET, //THUS PREVENTING ORDERMODIFY ERROR 1 //ORDERMODIFY ERROR 1: DOING THE SAME THING OVER & OVER AGAIN WITHOUT CHANGING ANYTHING && (orderStopLoss > orderOpenPrice)) { trade.PositionModify( orderTicket //CHOOSE THE CORRECT TICKET ,(orderOpenPrice - (Ask-Bid)) // SL HAS BEEN CHANGED ,orderTakeProfit); // TAKE PROFIT NOT CHANGED, ONLY THE STOPLOSS Print("the OrderGetTicket Value is ",orderTicket); } } } } } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Any leads on how do i make this much more efficient and not make my strategy tester load slowly, i don't know where to start.