Publishing in CodeBase - page 4

 
Osmar Sandoval Espinosa #:
Here is the code attached!

For me, this code fails validation before the test on M1 is run.


 

Osmar Sandoval Espinosa #:
Here is the code attached!

               if(CheckMoneyForTrade(_Symbol, minLot, ORDER_TYPE_BUY))  // Checking if there is enough money
                 {
                  double tp = rangeHigh + (rangeHigh -rangeLow);        // calculating the tp for the buy: rangehigh + size of the range
                  trade.Buy(minLot, _Symbol, 0, rangeLow, tp);          // entering a buy position
                  isTrade = false;                                      // deactivating the possibility to trade (only 1 trade a day)
                 }
               else
                 {
                  Print("Not enough margin for Buy trade");
                  isTrade = false;                                      // deactivating the possibility to trade (only 1 trade a day)
                 }

There are two potential causes of the invalid stops error visible to the naked eye:

  1. You do not normalize the price of SL/TP.
  2. You don't check the stop level.

You should learn how to properly normalize the price and how to check the stop level before placing a SL/TP.

[edit] By stop level I mean SYMBOL_TRADE_STOPS_LEVEL

 
Vladislav Boyko #:

There are two potential causes of the invalid stops error visible to the naked eye:

  1. You do not normalize the price of SL/TP.
  2. You don't check the stop level.
You should learn how to properly normalize the price and how to check the stop level before placing a SL/TP.

This version should have those corrections: 

 
Osmar Sandoval Espinosa #:

This version should have those corrections: 

double tp = rangeHigh + (rangeHigh - rangeLow);             // calculating the tp for the buy: rangehigh + size of the range

There is still no SYMBOL_TRADE_STOPS_LEVEL check and you should normalize the tp variable.

Furthermore, NormalizeDouble isn't the best way to normalize prices. Although it might even be sufficient for the validator (I haven't tested it), if you're committed to writing robust code, see the post below.

Forum on trading, automated trading systems and testing trading strategies

How To Manage 0.5 or 0.05 Price Steps (Tick Value, Tick Size) in order to avoid Error 130

Fernando Carreiro, 2018.01.04 12:13

You must NOT use NormalizeDouble(). You must use the Tick-Size to correctly set the price values. This has been discussed on the forum many times, so do a search but the most common post you will see goes something like this ...

In essence, make sure that your price quotes, are properly aligned to the Tick size (see following examples).

...
double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
...
double normalised_price = round( price / tick_size ) * tick_size;
...
// Or use a function
double Round2Ticksize( double price )
{
   double tick_size = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
   return( round( price / tick_size ) * tick_size );
}

You may also benefit from reading this: https://www.mql5.com/en/forum/223705#comment_6279080

 
Vladislav Boyko #:
SYMBOL_TRADE_STOPS_LEVEL

Is this version better?

Also I asked Vladimir Karputov for help, he did some modifications from the code and had this on his CodeBase validation:

I think that me not being able to publish is a thing of my account or something like that, do you know who can I contact?

 
Osmar Sandoval Espinosa #:

Is this version better?

Also I asked Vladimir Karputov for help, he did some modifications from the code and had this on his CodeBase validation:

I think that me not being able to publish is a thing of my account or something like that, do you know who can I contact?

On my end, the file you attached can be published. As it turns out, having trading operations on the M1 chart is not a mandatory requirement.

Do I understand correctly that you cannot publish that file?


 

Yes, I cannot publish it. :/


Alexey Petrov said me this: 

with my past code, but I still can't publish...

 
Osmar Sandoval Espinosa #:

Yes, I cannot publish it. :/

Alexey Petrov said me this: 

with my past code, but I still can't publish...

Did you replace what Alexey Petrov suggested you replace (not visible in your screenshot)?

 
Vladislav Boyko #:

Did you replace what Alexey Petrov suggested you replace (not visible in your screenshot)?

In that moment, yes, it was the image size, but that was for my past code.


 
Osmar Sandoval Espinosa #:

In that moment, yes, it was the image size, but that was for my past code.

Try creating a new codebase publication. If the "publish" button is not available for a new publication, please attach a screenshot similar to my recent one here.