Scaling In or Pyramiding every time Trailing Stop moves to breakeven

monaphilips
31
monaphilips  

Good day guys,

I am trying to code an EA that opens a new trade as soon as the trailing stop for the previous entry is at breakeven. I want to do this at least 5 times when the trailing stop is above the previous entry price.

//2nd Sell Order
OrderSelect(SellTicket,SELECT_BY_TICKET);
if(StopLoss < OrderOpenPrice())
        {
                if(AFastMA < BFastMA && BuyMarketCount(Symbol(),MagicNumber) == 1)
                        {

                                //Open Sell Order
                                SellTicket = OpenSellOrder(Symbol(),LotSize,UseSlippage,MagicNumber);                           
                        }
        }

Thank you.

William Roeder
25090
William Roeder  
monaphilips: I am trying … I want
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum 2018.05.12

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help 2017.04.21

monaphilips
31
monaphilips  
William Roeder:
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum 2018.05.12

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help 2017.04.21

This is what i tried to do, i tried to make the EA open a new trade each time the stop loss is above the previous open price:

Keith Watford
Moderator
31245
Keith Watford  
monaphilips:

This is what i tried to do, i tried to make the EA open a new trade each time the stop loss is above the previous open price:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

monaphilips
31
monaphilips  
Keith Watford:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

Ok thank you. Post updated.
monaphilips
31
monaphilips  
monaphilips:
Ok thank you. Post updated.
Pls can you share the link for MQL$ & Metatrader 4? I find it hard getting into that forum given that i joined the MQL5 community.
Keith Watford
Moderator
31245
Keith Watford  
monaphilips:
Pls can you share the link for MQL$ & Metatrader 4? I find it hard getting into that forum given that i joined the MQL5 community.

You are posting in it now.

Link

monaphilips
31
monaphilips  
Ok thank you.
William Roeder
25090
William Roeder  
OrderSelect(SellTicket,SELECT_BY_TICKET);
if(StopLoss < OrderOpenPrice())
  1. You are selecting by ticket. No where do you check if the order is still open.
  2. StopLoss is a variable. It is not the order's SL.
monaphilips
31
monaphilips  
William Roeder:
  1. You are selecting by ticket. No where do you check if the order is still open.
  2. StopLoss is a variable. It is not the order's SL.
Ok, pls how do i do that? "SellMarketCount"? Or do i give each order a specific description?
monaphilips
31
monaphilips  

This is what I did although it is still not working:

I selected the previous order and checked to see if the price (Close[1]) has moved a certain distance (Pyramid) in my favour before opening a new order:

Pls what is wrong with the code?

if(ABuyTicket > 0)
         {
         OrderSelect(ABuyTicket,SELECT_BY_TICKET);
         OpenPrice = OrderOpenPrice();
         double StopPrice = OrderStopLoss();
         
         //Open 2nd Buy Order
         if(((OpenPrice + (Pyramid * PipPoint(Symbol()))) < Close[1]) && (Close[1] > AHigh)
         && (equity > balance) && (BuyMarketCount(Symbol(),MagicNumber) < 2))
            {
            BBuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);

            //2nd Buy Order Modification
            if(BBuyTicket > 0 && (StopLoss > 0 || TakeProfit > 0))
               {
               OrderSelect(BBuyTicket,SELECT_BY_TICKET);
               OpenPrice = OrderOpenPrice();

               //Calculate and Verify Stop Loss (and Take Profit)
               BuyStopLoss = CalcBuyStopLoss(Symbol(),StopLoss,OpenPrice);
               if(BuyStopLoss > 0)
                  BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,5);

               BuyTakeProfit = CalcBuyTakeProfit(Symbol(),TakeProfit,OpenPrice);
               if(BuyTakeProfit > 0)
                  BuyTakeProfit = AdjustAboveStopLevel(Symbol(),BuyTakeProfit,5);

               //Add Stop Loss (and Take Profit)
               AddStopProfit(BBuyTicket,BuyStopLoss,BuyTakeProfit);
               }
            }
         }