Need a Debugging for a small piece of my code

 
//-------This is part of the EA....for now just assume that Prior "if" Conditions has led to MyOrderType = 7.
//-------"%$" labels the 261.8 Fib level with a price, rather then just 261.8. MAClose has already been calculated.
   if(MyOrderType == 7)
    {
         ObjectCreate("FibHigh", OBJ_FIBO, 0, 0, MAHigh, 0, MAClose);
         ObjectSetFiboDescription("FibHigh", 7, "%$");
         MyOrderType = 4;
    }     
      
      
             
//---
 
   if(MyOrderType == 4)      
   
    {   
          
        OrderSend(Symbol(), OP_BUY, 1, Ask, 3, MAClose, StrToDouble(ObjectGetFiboDescription("FibHigh", 7)), 
        "Moving Order", 00001, 0, Green);
        
         MyOrderType = 6;
            
            if(OrdersTotal() < 0)
             {
               Print("OrderSend failed with error #",GetLastError());
             }
I can't figure out what's wrong in the code above. When I run the Strategy Tester. ..the order is put in, but the take profit is not put in. Could someone please help?

-J
 
Graphic objects are not drawing in backtest.
 
See Testing Features and Limits in MetaTrader 4

Special Features of Optimization Process

  • Nothing is output in the journal (either Print() function)

    This was done in order to accelerate the testing and save disk space. If complete logs are output the journal files will need hundreds of MByte.

  • Draw objects are not really set

    The objects are disabled in order to accelerate the testing.

  • "Skip useless results" function is used

    In order not to garble the table and chart with testing results, the possibility to skip very bad results is used. This function can be enabled in context menu of "Optimization Results" -> &quotSkip useless results" tab.




 
Rosh:
See Testing Features and Limits in MetaTrader 4

Special Features of Optimization Process

  • Nothing is output in the journal (either Print() function)

    This was done in order to accelerate the testing and save disk space. If complete logs are output the journal files will need hundreds of MByte.

  • Draw objects are not really set

    The objects are disabled in order to accelerate the testing.

  • "Skip useless results" function is used

    In order not to garble the table and chart with testing results, the possibility to skip very bad results is used. This function can be enabled in context menu of "Optimization Results" -> &quotSkip useless results" tab.







So the code looks correct, then?

I believe I didn't run the test with Optimization being on.

I just want to make sure that I got the "Take Profit" Parameter correct in OrderSend. If that's how it would be done to translate the Price that the Fib Level is at into a double?
 
Use NormalizeDouble(Price,Digits)
 
https://docs.mql4.com/trading/OrderSend

At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a security differing from the current one, the MarketInfo() function must be used with MODE_BID or MODE_ASK parameter for the latest quotes for this security to be obtained. Calculated or unnormalized price cannot be applied. If there has not been the requested open price in the price thread or it has not been normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE) will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE) will be generated independently on the slippage parameter. If the requested price is out of date, but present in the thread, the position will be opened at the current price and only if the current price lies within the range of price+-slippage.
 
OrderSend(Symbol(), OP_BUY, 1, Ask, 3, MAClose, NormalizeDouble(StrtoDouble(ObjectGetFiboDescription("FibHigh",7)),4) , 
"Moving Order", 00001, 0, Green);

Is that how the code should be for OrderSend then? If so- then that isn't working either.

-j
 
Okay-

I think I figured out the problem, but I'm not sure how to fix it-

ObjectSetFiboDescription("FibHigh", 7, "%$");
That piece of the code changed the 7th fib. level (268.1) to the current price it is set at. Rather then leaving the default label "268.1", I changed the description to "%$" which allows the price to be shown on the chart window I'm looking at.
So I thought, when I would do-

ObjectGetFiboDescription("FibHigh",7);
That would pull up the price, rather then "%$", being that it changes the description on the chart window.
However- when I made a test code, which was this:

double  MAHigh, MAClose, MALow;
      
MAHigh = iMA(NULL,0,34,0,MODE_SMA,PRICE_HIGH,0);
MAClose = iMA(NULL,0,34,0,MODE_SMA,PRICE_CLOSE,0);
MALow = iMA(NULL,0,34,0,MODE_SMA,PRICE_LOW,0);
      
ObjectCreate("FibHigh", OBJ_FIBO, 0, 0, MAHigh, 0, MAClose);
ObjectSetFiboDescription("FibHigh",7,"%$");
Print(ObjectGetFiboDescription("FibHigh",7));
The Expert Printed "%$", even though the chart showed the 268.1 fib level as 1.3608 (which was the current price).

So the question NOW is either- How do I get the price rather then "%$"?

Or is there another way rather then ObjectGetFiboDescription to get the price that the 268.1 level is at?

-J
 
Try this solution:

Fibo_0=ObjectGet("FibHigh",OBJPROP_PRICE1);
Fibo_100=ObjectGet("FibHigh",OBJPROP_PRICE2);
...
Fibo_N_percent=(Fibo_100-Fibo_0)*N/100+Fibo_0;
 
Rosh:
Try this solution:

Fibo_0=ObjectGet("FibHigh",OBJPROP_PRICE1);
Fibo_100=ObjectGet("FibHigh",OBJPROP_PRICE2);
...
Fibo_N_percent=(Fibo_100-Fibo_0)*N/100+Fibo_0;


What does N mean? in N/100- It is giving me a error message that N is not defined.
 

Nevermind. I can figure out what N means with Algebra.

Actually though- it didn't work at first....

But then I tried:

         Fibo_0H=ObjectGet("FibHigh",OBJPROP_PRICE1);
         Fibo_100H=ObjectGet("FibHigh",OBJPROP_PRICE2);
         Fibo_N_percent1=(Fibo_100H-Fibo_0H)*7/100+Fibo_0H;
         DoubleToStr(Fibo_N_percent1,4);
         Buy = Fibo_N_percent1;
And for some reason that worked. So I think I'm good.
Reason: