Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 398

 
Link_x:
I am copying it again.

You need to write a part of your trading robot's code, so that it would perform a deal once, if trading conditions are fulfilled.
For example:
1) If Line_1 is higher than Line_2, a buy trade is executed,
2) The deal is closed at SL or TP,
3) If Line_1 is higher than Line_2, a trade is not executed until the conditions are changed. .
...

etc.


(3) The paragraph is unclear. "...until the conditions change" - what conditions are being referred to is not stated.

Do you only need to open a buy order? It is also not clear whether several orders may exist in the market simultaneously or only one order.

 
fozi:

Hi camradics.

Who can trade the SP500 via MT4-5 ?


mmcis has a _SP500 mt4 demo

But it says Trade: No.

Maybe it is only on demo, i dont know.

 
Link_x:
I am copying it again.

You have to write a part of the code of a trading robot, so it would make a deal once, if the trading conditions are fulfilled.
For example:
1) If Line_1 is higher than Line_2, then a buy trade is executed,
2) The deal is closed at SL or TP,
3) If Line_1 is higher than Line_2, a trade is not executed until conditions change. .

If conditions change, i.e. Line_2 is higher than Line_1, a trade is executed. Then everything is repeated.
1) If Line_2 is higher than Line_1, a buy trade is executed,
2) The trade is closed at SL or TP,
3) If Line_2 is higher than Line_1, a trade is not executed until conditions change. .

And.
1) If Line_1 is higher than Line_2, a buy trade is executed..,
2) The trade is closed at SL or TP,
3) If Line_1 is higher than Line_2, the trade is not executed until the conditions change. .

etc.


I have thought about it and I think I understand, but I still want confirmation if I've got it right.

There is always only one order in the market. The order is always opened when the condition changes and always only to buy.

 
khorosh:

(3) The paragraph is unclear. "...until the conditions change" - what conditions are being referred to is not stated.

Do you only need to open a buy order? It is also not clear whether several orders can exist simultaneously in the market or only one order.

Both Buy and Sell.
Only one order.

....
 
Link_x:
Both Buy and Sell.
Only one order.

....
Your assignment doesn't say a word about sell, only buy everywhere.
 
khorosh:
Your assignment doesn't say a word about sell, only buy.


My mistake. I'll fix it. :)


1) If Line_1 is higher than Line_2, then we make a buy trade,
2) The trade is closed at SL or TP,
3) If Line_1 is above Line_2, a trade is not executed until conditions change. .

If conditions change, i.e. Line_2 is higher than Line_1, a trade is executed. Then everything is repeated.
1) If Line_2 is higher than Line_1, a sell trade is executed,
2) The trade is closed at the SL or TP,
3) If Line_2 is above Line_1, a trade is not executed until conditions change. .

And.
1) If Line_1 is higher than Line_2, a buy trade is executed..,
2) The trade is closed at SL or TP,
3) If Line_1 is above Line_2, a trade is not executed until conditions change. .
 
A visual explanation:
Files:
 
Link_x:

I messed up. I'll fix it. :)


1) If Line_1 is higher than Line_2, a buy trade is executed,
2) The trade is closed at SL or TP,
3) If Line_1 is above Line_2, a trade is not executed until conditions change. .

If conditions change, i.e. Line_2 is higher than Line_1, a trade is executed. Then everything is repeated.
1) If Line_2 is higher than Line_1, a sell trade is executed,
2) The trade is closed at the SL or TP,
3) If Line_2 is above Line_1, a trade is not executed until conditions change. .

And.
1) If Line_1 is higher than Line_2, a buy trade is executed..,
2) The trade is closed at SL or TP,
3) If Line_1 is above Line_2, a trade is not executed until conditions change. .

int start()
  {
//----
   
   if(Lin1>Lin2)
     {
      if(!ExistPositions("0", -1, -1, 0))
        {
         if(OrdersHistoryTotal()<1 || GetTypeLastClosePos("0", -1)==OP_SELL)
           {
            OpenPosition("0",OP_BUY,NormalizeDouble(Ask-SL*Point,Digits),
                       NormalizeDouble(Ask+TP*Point,Digits), -1);
           }
        }                         
     }
   if(Lin1<Lin2)
     {
      if(!ExistPositions("0", -1, -1, 0))
        {
         if(OrdersHistoryTotal()<1 || GetTypeLastClosePos("0", -1)==OP_BUY)
           {
            OpenPosition("0",OP_SELL,NormalizeDouble(Bid+SL*Point,Digits),
                          NormalizeDouble(Bid-TP*Point,Digits), -1);
           }
        }                         
     }  
//----
   return(0);
  }
Чтобы код работал нужно ещё записать коды всех использованных функций KimIV вне тела функции start() и
определить все значения констант и переменных ошибки по которым будут выданы при компиляции ввиду 
того что здесь они не определены..

	          
 

Happy New Year to all! Happiness, good luck, love and of course huge profits to everyone! =))


If you are an expert, please check the function for errors. The main point of this function: it should calculate a lot required in order to make the next open order cover its losses in a certain amount of points in case of closing the order grid.

double FindRightLot (int otype)
{
  double Lot=0; double TotalLot=0;
  for (int i = OrdersTotal()-1; i>0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       {
         if (otype == OP_BUY)
         {
           Lot = NormalizeDouble ((OrderOpenPrice()-Bid)*OrderLots()/TP,2); // ТP это то к-во пунктов, за которое след. ордер должен закрыть убыток
           if (Lot>0) // т.е. нас интересуют только убыточные ордера
           {
             TotalLot=TotalLot+Lot;
           }
         }
           
       
         else if (otype == OP_SELL)
         {
           Lot = NormalizeDouble ((Ask-OrderOpenPrice())*OrderLots()/TP,2);
           if (Lot>0)// выбираем только убыточные
           {
             TotalLot=TotalLot+Lot;
           }
           
         }
       }
     }
   }
   return (TotalLot);
   
 }
 
artmedia70:

You're looking in the wrong direction. Are you making for the tester or for the real thing? The difference is significant.

If for real, forget about the flags that can be lost in abnormal situations. It's better to look for everything in the trading environment.

He can't do anything! Only wants to be written to! It's no use explaining! There's no logic at all! An incorrigible loser!
Reason: