Script for pending orders ?

 
Have a question,

Is it possible to have a script or something like that, that can contain a price for the order to trigger, with a fixed SL and TP ?

I found some that come close with fixed SL and TP, but price is WindowOn Dropped, wich isn't the price it should be.

To be clear, it should be possible to enter a price for the trigger, either long or short, with fixed SL and TP, so is it possible to enter a trigger price as a extern var ?

Something like this with regards to Blackhawk :


#property show_inputs
//#property show_confirm

extern double Lots    = 0.01;
extern int Slippage   = 3;
extern int Stop_Loss  = 50;
extern int Take_Profit = 50;

//+------------------------------------------------------------------+
//| script "Open a new Sell Order"                                    |
//+------------------------------------------------------------------+
int start()
  {
   double Price = WindowPriceOnDropped();
   bool   result;
   int    cmd,total,error,slippage;
   
//----
   int NrOfDigits = MarketInfo(Symbol(),MODE_DIGITS);   // Nr. of decimals used by Symbol
   int PipAdjust;                                       // Pips multiplier for value adjustment
      if(NrOfDigits == 5 || NrOfDigits == 3)            // If decimals = 5 or 3
         PipAdjust = 10;                                // Multiply pips by 10
         else
      if(NrOfDigits == 4 || NrOfDigits == 2)            // If digits = 4 or 3 (normal)
         PipAdjust = 1;            
//----   
   
   slippage = Slippage * PipAdjust;
   
   double stop_loss = Price + Stop_Loss * Point * PipAdjust;
   double take_profit = Price - Take_Profit * Point * PipAdjust; 
   
   if(Bid > Price)
   {
   result = OrderSend(Symbol(),OP_SELLSTOP,Lots,Price,slippage,stop_loss,take_profit,"",0,0,CLR_NONE);
   }
   if(Bid < Price)
   {
   result = OrderSend(Symbol(),OP_SELLLIMIT,Lots,Price,slippage,stop_loss,take_profit,"",0,0,CLR_NONE);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Please use this to post code . . . it makes it easier to read.

You could add a price label to your chart, move the price label to where you want to trigger the pending order then when the script is run it reads the price label and sends the order.

 

Your right Raptor, looking much better :)

But not so much of a coder, how do I add a pricelabel to a chart ?

 
hannibal:

Your right Raptor, looking much better :)

But not so much of a coder, how do I add a pricelabel to a chart ?

You add it manually or you add it via code using Objects, https://docs.mql4.com/objects use https://docs.mql4.com/objects/ObjectCreate with object type OBJ_ARROW and then set OBJPROP_ARROWCODE ( https://docs.mql4.com/constants/objects/properties ) to be SYMBOL_RIGHTPRICE or SYMBOL_LEFTPRICE

Once you have it on your chart to position it where you want the Order placed, then your script, when run, can read it's value using https://docs.mql4.com/objects/ObjectGet

 

managed to get the pricelabel on the chart manually, and it seems to work, more or less, thx

will study on the ordersetup

Reason: