I'm learning to write an advisor... - page 2

 
Figar0 >> :

...For the non-programmer novice, it might make a difference...

)) That's a big word for me! I've been in forex for only 2.5 years... For all this time I earned 2 times: 1st time on demo (I increased my deposit 50 times), 2nd time on real (result is more modest)

I made only one conclusion: there is no discipline! I`ve decided to try to write something that would not depend on my emotions.)

 
rid >> :

And to help you think quicker, first run your expert through ALL TICS and the result here, please.

The test went through all the ticks anyway! You can see it in the pictures...

 

I seem to have messed up something in this code...

void ClosePos()
   {
      double pp;

        if (OrderType()==OP_BUY)
          {
            pp=MarketInfo(OrderSymbol(), MODE_BID);
            OrderClose( OrderTicket(), OrderLots(), Bid, 0, Blue);
          }
        if (OrderType()==OP_SELL)
          {
            pp=MarketInfo(OrderSymbol(), MODE_ASK);
            OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);
          }
   }


I keep getting an error in the log...

invalid ticket for OrderClose function
OrderClose error 4051
OrderSend error 130

This check to close goes before the opposite input signal...

if there is a buy signal

(OrderType()==OP_BUY)
close the current sell

OrderClose( OrderTicket(), OrderLots(), Bid, 0, Blue)

And vice versa...

But the whole log fills up with an error...

It looks like it tries to close on every tick... But there are no conditions...



 
Where is OrderSelect?
 
I don't know) That's why I'm here... to get it right...
 
sergeev >> :
Where is OrderSelect?

Read about this function... converted to this variant:

void ClosePos()
   {
      double pp;
        if (OrderSelect(0, SELECT_BY_POS)==true) // Если есть открытый ордер
            { 
               if (OrderType()==OP_BUY)
                  {
                  pp=MarketInfo(OrderSymbol(), MODE_BID);
                  OrderClose( OrderTicket(), OrderLots(), Bid, 0, Blue);
                  }
               if (OrderType()==OP_SELL)
                  {
                  pp=MarketInfo(OrderSymbol(), MODE_ASK);
                  OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);
                  }
            }      
   }
 

I would have liked it if it wasn't for the quality of the modelling

 
What does it depend on?
 

search for it, you need to download and recalculate the history

 
ALex2008 писал(а) >>
What does it depend on?

Download minute candles (e.g. from Alpari) and test on minute candles.

You cannot test a 5 pips stop on 4-hour candlesticks.