Download MetaTrader 5

Expert Advisor: I need help.

To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Trololo Tromberino
73
Trololo Tromberino 2015.07.29 12:49 

Hi guys,


i´m a new coder and started programming a new ea.

But i have a problem: My order doesn´t get send.

The mt4 backtest says: invalid stoploss #130. I searched an found out, that i need to convert my signal.

I want the Stoploss some points (variable) below the SuperTrend-Indicator.

So look at this:


double TrailingStopLoss = iCustom(NULL,0,"SuperTrend",10,3.0,0,0); 

    

double sl = Bid - (TrailingStopLoss*Point);

........

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl,0,"My order",16384,0,clrGreen); //Market Order long


What did i wrong?


Would be so glad for help.


Best regards.

Vasyl Nosal
18557
Vasyl Nosal 2015.07.29 15:26  
TTromberino:

Hi guys,


i´m a new coder and started programming a new ea.

But i have a problem: My order doesn´t get send.

The mt4 backtest says: invalid stoploss #130. I searched an found out, that i need to convert my signal.

I want the Stoploss some points (variable) below the SuperTrend-Indicator.

So look at this:


double TrailingStopLoss = iCustom(NULL,0,"SuperTrend",10,3.0,0,0);     

double sl = Bid - (TrailingStopLoss*Point);

........

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl,0,"My order",16384,0,clrGreen); //Market Order long


What did i wrong?


Would be so glad for help.


Best regards.

Write

Alert(sl," ",Ask);

Then let me see. 

whroeder1
14532
whroeder1 2015.07.29 18:18  
TTromberino:
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl,0,"My order",16384,0,clrGreen); //Market Order long

What did i wrong?

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes (OrderSend) and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Keith Watford
Moderator
9650
Keith Watford 2015.07.29 19:54  
double TrailingStopLoss = iCustom(NULL,0,"SuperTrend",10,3.0,0,0);      

double sl = Bid - (TrailingStopLoss*Point);

........

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl,0,"My order",16384,0,clrGreen); //Market Order long

Your sl calculation doesn't make sense

if Point=0.00001 and the indicator value is 1.50000

double sl = Bid - (TrailingStopLoss*Point);

double sl = Bid - (1.50000*0.00001);

double sl = Bid - 0.000015;

 Which is certainly too close to the current price

Trololo Tromberino
73
Trololo Tromberino 2015.07.30 08:22  

Thanks guys for the superfast help!

Actually i changed that problem:

int ticket;
double TrailingStopLoss = iCustom(NULL,0,"SuperTrend",10,3.0,0,0);      
double sl = TrailingStopLoss;

I just wrote it in the start function, now its working.

But i got another problem...

I want a Trailingstop based on the SuperTrend-Indicator.


if (Bid > sl) ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl,0, "My Order",16384,0,Green);  //Order soll erstellt werden. // I open my Order
         if(ticket == 0)
             {
                   Print("OrderSend failed with error #",GetLastError());
                
              }
          else
          Print("OrderSend placed successfully #" + string(ticket));

          
if( OrderSelect(ticket,SELECT_BY_TICKET) && OrderCloseTime()==0 ) //Trailingstop, der auf Basis des SuperTrend Indikators nachgezogen werden soll. (Nur für Long) // This is where the Trailingstop is initialized
{
    if( OrderType()==OP_BUY ) 
    {
        bool ordermodify = OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-sl,0,0); //order modify for the ST-Indicator. 
        if (ordermodify == false)
        {Alert ("Stoploss NICHT nachgezogen! ERROR!");} //Failalert
        else
        {Alert ("StopLoss nachgezogen");}
    }           
}  

As you see i try to initialize a trailingstop. The first stop is set right, but it doesn´t move, when i should. It just stands on the first position, where i opened my position.


Hope i edited everything in the right way for you guys.


I´m very glad that you are helping me.


Best regards.

Keith Watford
Moderator
9650
Keith Watford 2015.07.30 08:35  
double TrailingStopLoss = iCustom(NULL,0,"SuperTrend",10,3.0,0,0);      
double sl = TrailingStopLoss;


bool ordermodify = OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-sl,0,0);
What do you think Open[0]-sl equals?
Trololo Tromberino
73
Trololo Tromberino 2015.07.30 08:39  
GumRai:
What do you think Open[0]-sl equals?

Openprice of the new candle  - the stoploss point.

In my opinion i should get out the new stoploss level .

Am i wrong?

Keith Watford
Moderator
9650
Keith Watford 2015.07.30 10:11  
TTromberino:

Openprice of the new candle  - the stoploss point.

In my opinion i should get out the new stoploss level .

Am i wrong?

Have a look on your chart, what is the value of the supertrend indicator?

What do you get if you deduct that value from the candle open price?

Do you really want to use that as your stoploss? 

Trololo Tromberino
73
Trololo Tromberino 2015.07.30 10:49  

Soo let me explain:

The stoploss works like this:

So as you see, the stoploss is just some points below the SuperTrend-Indicator. With every new period, the sl should get below the new ST-Indicator-value.

But as you can see, it just stays below the first point and doesn´t move as it should.

Why everyone is asking, if i want to use that as a stoploss?`In my opinion it works pretty well..... O.o

And to the deduct to the openprice...the definition of the st-indicator is calculated from the closingprice of the last candle...and opening and closing price are most of the time the same.... so what do you mean?


Thanks for spending your time for my problem, i´m so glad. :)


Best regards.

Keith Watford
Moderator
9650
Keith Watford 2015.07.30 12:32  

Did you do as I asked?

Have a look on your chart, what is the value of the supertrend indicator?

What do you get if you deduct that value from the candle open price?

Do you really want to use that as your stoploss?  

 Show me the value of the supertrend indicator.

Show me the candle open price

Show me the calculation for candle open price-supertrend value 

Do you really want to use that as your stoploss? 

Trololo Tromberino
73
Trololo Tromberino 2015.07.30 13:51  

So...here you go:

2015.07.30 15:49:21.171 EURUSD,M15: 91516 tick events (2051 bars, 936736 bar states) processed in 0:00:27.129 (total time 0:00:29.235)
2015.07.30 15:49:21.171 2015.06.30 08:27  Tester: order #1 is closed
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.171 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.171 2015.06.30 08:27  Tester: stop button pressed
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.170 2015.06.30 08:27  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
.
.
.
.
.
.
.
.
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.87991
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Openprice #1.12009
2015.07.30 15:49:21.154 2015.06.30 08:25  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Fehler beim Positionsliquidieren.
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.88484
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Openprice #1.11516
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Fehler beim Positionsliquidieren.
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.88484
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Openprice #1.11516
2015.07.30 15:48:58.561 2015.06.26 20:30  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:48:54.125 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Fehler beim Positionsliquidieren.
2015.07.30 15:48:54.125 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.8823
2015.07.30 15:48:54.125 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Openprice #1.1177
2015.07.30 15:48:54.125 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:48:54.061 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Fehler beim Positionsliquidieren.
2015.07.30 15:48:54.054 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Open - Supertrend #-2147483645.8823
2015.07.30 15:48:54.054 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Openprice #1.1177
2015.07.30 15:48:54.054 2015.06.26 16:30  Neuer Versuch Long only EURUSD,M15: Supertrend #2147483647
2015.07.30 15:48:54.045 Neuer Versuch Long only inputs: Lots=1; Slip=2; 
2015.07.30 15:48:54.041 TestGenerator: unmatched data error (volume limit 623 at 2015.07.24 13:00 exceeded)
2015.07.30 15:48:54.039 TestGenerator: unmatched data error (volume limit 349 at 2015.07.23 22:00 exceeded)
2015.07.30 15:48:51.939 TestGenerator: current spread 16 used

Do you mean this? How this helps?
12
To add comments, please log in or register