active position price

 

i'm new and hung out somewhere. I would be glad if you help.


If the close price is up to 20 higher than my active end position, I would like to reopen new position.

How can I assign my last active position price to a variable? and "If the last candle closing price has increased at least 20 from my last open traded price" how can I stipulate it?

 
Emre Bahtlı:

i'm new and hung out somewhere. I would be glad if you help.


If the close price is up to 20 higher than my active end position, I would like to reopen new position.

How can I assign my last active position price to a variable? and "If the last candle closing price has increased at least 20 from my last open traded price" how can I stipulate it?

show your attempt code. 

 
Mohamad Zulhairi Baba:

deneme kodunuzu gösterin. 

 
  // Buy
  
  if (rsi5m <= 30
  && buyopen==0) {
  openbuyposition();
  buyopen=1;
  lastpositionprice=Close[1];
  Sleep(300000);
        }
        
        //again open buy
  
  if (buyopen==1 && (lastpositionprice-Close[1])/ Point > 20)  {

  openbuyposition();
  lastpositionprice=Close[1];
  Sleep(300000);
  }
        
        //close buy pos
   
   if (rsi5m >=50 && buyopen==1){

   CloseOrders();
   buyopen=0;
   lastpositionprice="";
   }
   
                                         
  } //OnTick Close
  
  
  void openbuyposition()
  
  
  { //open void
  
  int tickets = OrderSend(Symbol(),OP_BUY,lot,Ask,10,0,0,"Buy İşlemi Açıldı",OrderMagicNumber(),0,clrBlue);

  lot=lot*2;
  openbuy=1;
 
 
sorry for inexperienced things. If you want, you can change the whole. and in this way I will have learned new things.
 
Emre Bahtlı:

i'm new and hung out somewhere. I would be glad if you help.


If the close price is up to 20 higher than my active end position, I would like to reopen new position.

How can I assign my last active position price to a variable? and "If the last candle closing price has increased at least 20 from my last open traded price" how can I stipulate it?

Try this

//+------------------------------------------------------------------+
double LastOrder ()
{
   double LastOrderPrice;
   LastOrderPrice=0;
 
for(int i=0;i<OrdersTotal();i++) 
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()!=Symbol()) continue; 
         if(OrderType()==OP_BUY)
         LastOrderPrice=(OrderOpenPrice());
      if(OrderType()==OP_SELL)
         LastOrderPrice=(OrderOpenPrice());   
   }
   return (LastOrderPrice);
   
}
//+------------------------------------------------------------------+
You can use that for your last order price
LastOrder ()
that code above not including the Magicnumber, if you want to add that magic number, you may change line of order select
 if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
       if(OrderSymbol()!=Symbol() ||    
       OrderMagicNumber()!=MagicNumber) 
       continue;        
 
this is the last case. but only buys 1 time: / somewhere there is a problem but i could not understand.
Files:
This website uses cookies. Learn more about our Cookies Policy.