inquiry on Program Logic of Trailing Stop

 

Salutations!

So I was tinkering with my trailing stop code template, which kinda is as follows:

         if((OrderType()==OP_BUY) && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber))  
/*This*/       if((TrailingStop>0) && (Bid>OrderOpenPrice()+MyPoint*TrailingStop) && ((Bid>OrderStopLoss()+MyPoint*TrailingStop) || (OrderStopLoss()==0)))
               {
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*MyPoint,Digits),OrderTakeProfit(),0,Green))
                  Print("Error modify trailing stop "+string(GetLastError()));
               }
         }
         else 
         {
            if((OrderType()==OP_SELL) && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber))
            {
/*This also*/  if((TrailingStop>0) && (Ask<OrderOpenPrice()-MyPoint*TrailingStop) && ((Ask<OrderStopLoss()-MyPoint*TrailingStop) || (OrderStopLoss()==0)))
               {
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+MyPoint*TrailingStop,Digits),OrderTakeProfit(),0,Red))
                  Print("Error modify trailing stop "+string(GetLastError()));
               }
            }
         }

I would like to ask why when the codeblock || (OrderStopLoss()==0) is removed on the line marked "This", results during backtest are always the same.

But when the same codeblock is removed on the line marked "This also", results vary.

I understand that the codeblock in question acts as a safety net in case there is no input in StopLoss. But why will it only work on Sell orders and not on Buy orders?

Tried digging in MQL literature everywhere but yielded no results.

Responses are always appreciated.

Ciao!

 
Ibex Thales:

Salutations!

So I was tinkering with my trailing stop code template, which kinda is as follows:

I would like to ask why when the codeblock || (OrderStopLoss()==0) is removed on the line marked "This", results during backtest are always the same.

But when the same codeblock is removed on the line marked "This also", results vary.

I understand that the codeblock in question acts as a safety net in case there is no input in StopLoss. But why will it only work on Sell orders and not on Buy orders?

Tried digging in MQL literature everywhere but yielded no results.

Responses are always appreciated.

Ciao!

Because you did use a stoploss for each previously opened deals ?

I see no "This Also".

 
Icham Aidibe:

Because you did use a stoploss for each previously opened deals ?

I see no "This Also".

I may or may not use for each previously opened deals. I am creating a template flexible enough to accommodate either scenario.

Apologies for the This also. Added on the above post.

Thank you.

 
Ibex Thales:

Salutations!

So I was tinkering with my trailing stop code template, which kinda is as follows:

I would like to ask why when the codeblock || (OrderStopLoss()==0) is removed on the line marked "This", results during backtest are always the same.

But when the same codeblock is removed on the line marked "This also", results vary.

I understand that the codeblock in question acts as a safety net in case there is no input in StopLoss. But why will it only work on Sell orders and not on Buy orders?

Tried digging in MQL literature everywhere but yielded no results.

Responses are always appreciated.

Ciao!

Have you select the order using OrderSelect() ?