Register


Results 1 to 4 of 4

Thread: Code TrailingStop

  1. #1
    Cybermanu is offline Member
    Join Date
    Mar 2012
    Posts
    67

    Code TrailingStop

    Bonjour,

    Voici le code du TrailingStop à mettre dans vos EA.

    Déclarer la variable : TrailingStop (Extern double TrailingStop)

    et mettre le code Aprés le "int start()" évidement.

    Code:
    void TrailingStop()
    {
        for (int i=OrdersTotal()-1; i >= 0; i--)
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
            {
                double takeprofit = OrderTakeProfit();
                            
                if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop*PipValue*Point)
                {
                    if(TrailingStop > 0) 
                    {
                        if(Bid - OrderOpenPrice() > PipValue*Point * TrailingStop) 
                        {
                            if(OrderStopLoss() < Bid - PipValue*Point * TrailingStop) 
                            {
                                OrderModify(OrderTicket(), OrderOpenPrice(), Bid - PipValue*Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                            }
                        }                                         
                    }                                
                }                        
                if ((OrderType() == OP_SELL) && (OrderOpenPrice() - Ask) > (PipValue*TrailingStop*Point))
                {
                    if( TrailingStop > 0) 
                    {
                        if((OrderOpenPrice() - Ask) > (PipValue*Point * TrailingStop)) 
                        {
                            if((OrderStopLoss() > (Ask + PipValue*Point * TrailingStop)) || (OrderStopLoss() == 0)) 
                            {
                                OrderModify(OrderTicket(), OrderOpenPrice(), Ask + PipValue*Point * TrailingStop, takeprofit, 0, DarkOrange);
                            }
                        }
                    }
                }
            }            
            else
            Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
        }    
    }

    Bon trade !

  2. #2
    Phoeseb is offline Member
    Join Date
    Mar 2012
    Posts
    45
    bonjour, heu je fais copier/coller et cela fonctionne tous seul?
    je suis ultra novice en robot!

  3. #3
    Cybermanu is offline Member
    Join Date
    Mar 2012
    Posts
    67
    Heu ! non il faut déclarer la variable :

    Code:
    extern double TrailingStop=25;
    Phoeseb likes this.

  4. #4
    Phoeseb is offline Member
    Join Date
    Mar 2012
    Posts
    45
    merci beaucoup a vous!! j'y vais petit a petit lol ! la je suis a copier/coller 18erreus lol je mouline mais ca avance!!!!
    Last edited by Phoeseb; 04-30-2012 at 01:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.