Reverse Trade HELP

To add comments, please log in or register
Baptiste George
593
Baptiste George  

Hey,


The script is a simple EA that checks if a manuel trade (MagicalNumber == 0) closed with no profit.

Ex: When a SELL TRADE has been closed with no profit, so I would like to open straight away (market price) a OP_BUY


So I've added both way ("OP_BUYSTOP" && "OP_BUY") and only "OP_BUYSTOP seems to work but I would like to a "OP_BUY"


Please help : )


    
       // Get the last order handled by the EA the last time it was used. The value
       // defaults to zero if the global variable does not yet exist.   
       string strGlobalVariableName = WindowExpertName() + "_" + Symbol() + "_LastOrderCount";
       int LastHistoryCount = GlobalVariableGet(strGlobalVariableName);

       // Scan the order list. Doesn't matter whether this is done from zero upwards,
       // or from OrdersHistoryTotal() downwards. 
       
       for(int i = LastHistoryCount ; i < OrdersHistoryTotal(); i++)
        {
               if (OrderProfit() < 0
               &&  OrderSymbol() == Symbol() 
               &&  OrderType () == OP_SELL
               &&  OrderMagicNumber() == 0)
                    {
                      Alert("SHORT Trade Closed in loss!");
                      OrderSend(Symbol(), OP_BUYSTOP, LotSize, Ask+3*Point*10, 2, Ask-StopLoss*Point*10, Ask+TakeProfit*Point*10, "REVERSE Manuel Trade INDIRECT", 007,0, Green);
                      OrderSend(Symbol(), OP_BUY, LotSize, Ask, 2, Ask-StopLoss*Point*10, Ask+TakeProfit*Point*10, "REVERSE Manuel Trade DIRECT", 007,0, Green);
                      GetLastError();
                         }

        }
       // Store the last-order count in a global variable which persists across multiple uses of the EA
       GlobalVariableSet(strGlobalVariableName, OrdersHistoryTotal());
Simon Gniadkowski
17213
Simon Gniadkowski  
Is your Broker an ECN Broker ?
Baptiste George
593
Baptiste George  
Yes it is
Baptiste George
593
Baptiste George  

I've tested on Strategy Tester and both of trades have been opened.

But in Demo account it doesn't for "OP_BUY" : (

Simon Gniadkowski
17213
Simon Gniadkowski  
FrenchyTrader:

I've tested on Strategy Tester and both of trades have been opened.

But in Demo account it doesn't for "OP_BUY" : (

Correct, the Strategy Tester does not simulate an ECN broker.

Plenty to read here: http://crum.be/ecn

Essentially, you OrderSend with TP & SL set to 0, then OrderModify to set the SL & TP

Simon Gniadkowski
17213
Simon Gniadkowski  
FrenchyTrader:

I've tested on Strategy Tester and both of trades have been opened.

But in Demo account it doesn't for "OP_BUY" : (

If you take note of the return values from your OrderSend() and then Print the error, if there is one, you would have a good idea of what the issue is.
Baptiste George
593
Baptiste George  
Ok Thank you
Baptiste George
593
Baptiste George  

Now it works... : )


The last thing:

How can get the LotSize and Symbol of the last lost manuel trade, so the EA can open the opposition trade with the right information?

Baptiste George
593
Baptiste George  
Ok I got it.
William Roeder
20210
William Roeder  
FrenchyTrader:
How can get the LotSize and Symbol
You are already getting the Symbol in your IF STATEMENT. RTFM
EApuppy
5
EApuppy  

@Baptiste George

I am failry new to EAs and mostly trade manually, however understand the value of automating parts of my trading strategy to make life a little less stressful. Is it possible to have a basic stop and reverse trade code when if an existing open position closes by stop-loss, a new position is immediately opened in the reverse direction, so it would open at around the same price action level.

It only activates when a stop-loss has been reached. It should also ignore any other open positions, unless those also exit via their own specific stop loss levels, in which case new stop and reverse trade(s) are created at the price action levels of those respective positions.

The newly opened position(s) should follow default parameter settings and does not need any money management, no Martingale,  etc. or other features. However it must operate on any pair, indicators, timeframes and both 4 and 5 digit brokers.

I hope this makes sense? And thanks in advance!

12
To add comments, please log in or register