stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Script for placing pending orders
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1325
Page 1 of 5
Author:  Sgt.Forex [ Thu Dec 20, 2012 8:07 am ]
Post subject:  Script for placing pending orders

Hi,
does anyone of you have or know of a script that does the following:

For Buy pending:
When i drag it onto the chart, it will place a pending order X pips + Spread above LAST candles high?

For Sell panding:
The opposite...


Cheers
Philipp
Author:  SteveHopwood [ Thu Dec 20, 2012 12:18 pm ]
Post subject:  Re: Script for placing pending orders

Here you are Philipp.

CandleShift allows you to use the hi/lo of any candle you choose - defaults to the previous candle.

I knocked these together this morning, so sing out if anything is not quite right.

:D
Author:  Sgt.Forex [ Thu Dec 20, 2012 1:56 pm ]
Post subject:  Re: Script for placing pending orders

SteveHopwood wrote:Here you are Philipp.

CandleShift allows you to use the hi/lo of any candle you choose - defaults to the previous candle.

I knocked these together this morning, so sing out if anything is not quite right.

:D
Wow, nice one Steve! Thank you very much! :-)
I will report back.

Cheers
Author:  Sgt.Forex [ Thu Dec 20, 2012 2:27 pm ]
Post subject:  Re: Script for placing pending orders

Here is the report ;-)

I am getting an error message:

Code: Select all

2012.12.20 15:17:17	Philipp's Pending Sell Script XAUUSD.arm,H1: XAUUSD.arm Philipp's Pending Sell Script OP_SELLSTOP order send failed with error(4107): invalid price parameter for trade function
-> Buy pending worked on the same candle.

Cheers
Author:  SteveHopwood [ Thu Dec 20, 2012 3:04 pm ]
Post subject:  Re: Script for placing pending orders

Sgt.Forex wrote:Here is the report ;-)

I am getting an error message:

Code: Select all

2012.12.20 15:17:17	Philipp's Pending Sell Script XAUUSD.arm,H1: XAUUSD.arm Philipp's Pending Sell Script OP_SELLSTOP order send failed with error(4107): invalid price parameter for trade function
-> Buy pending worked on the same candle.

Cheers
Works fine here/ Make sure you are using it when it can work - can't send a sell stop if the market is already lower than the low of the previous candle.

:D
Author:  Sgt.Forex [ Thu Dec 20, 2012 3:33 pm ]
Post subject:  Re: Script for placing pending orders

Hmm, ok i will retry. But the Price wasn`t lower, than the low of the previous candle.

Cheers
Author:  Sgt.Forex [ Thu Dec 20, 2012 3:37 pm ]
Post subject:  Re: Script for placing pending orders

Sgt.Forex wrote:Hmm, ok i will retry. But the Price wasn`t lower, than the low of the previous candle.

Cheers
Tried to use it on XAU/USD -> only the buystop worked.
Tried to use it on EUR/CHF -> both worked.
Maybe its a "Gold bug" ? ;-)

Cheers
Author:  fx800 [ Sun Mar 03, 2013 11:13 am ]
Post subject:  Re: Script for placing pending orders

Hi Steve,

I am confused. Why is double spread = Ask - Bid, and not double spread = (Ask - Bid) * factor in your script code ?

Code: Select all

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
  
   RefreshRates();
   price = 0; stop = 0; take = 0;
   double spread = Ask - Bid;
  
   //Set up a dummy for functions that might not be called, so they do not disturb the punters.
   int x = 0;
   if (x > 0)
   {
      CloseEnough(0, 0);
   }//if (x == 0)
  
   price = High[CandleShift] + (AddToHighPips / factor) + (spread / factor);
   stop = CalculateStopLoss(OP_BUY);
   take = CalculateTakeProfit(OP_BUY);
   SendSingleTrade(OP_BUYSTOP, TradeComment, Lot, price, stop, take);
This will make the spread calculation in the price equals to (Ask - Bid)/factor instead of (Ask - Bid) which is already in the correct decimal.

Peter
Author:  SteveHopwood [ Sun Mar 03, 2013 12:53 pm ]
Post subject:  Re: Script for placing pending orders

fx8000 wrote:Hi Steve,

I am confused. Why is double spread = Ask - Bid, and not double spread = (Ask - Bid) * factor in your script code ?

Code: Select all

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
  
   RefreshRates();
   price = 0; stop = 0; take = 0;
   double spread = Ask - Bid;
  
   //Set up a dummy for functions that might not be called, so they do not disturb the punters.
   int x = 0;
   if (x > 0)
   {
      CloseEnough(0, 0);
   }//if (x == 0)
  
   price = High[CandleShift] + (AddToHighPips / factor) + (spread / factor);
   stop = CalculateStopLoss(OP_BUY);
   take = CalculateTakeProfit(OP_BUY);
   SendSingleTrade(OP_BUYSTOP, TradeComment, Lot, price, stop, take);
This will make the spread calculation in the price equals to (Ask - Bid)/factor instead of (Ask - Bid) which is already in the correct decimal.

Peter
Nice spot Peter. Thanks. I have a shell script that doesn't multiply the spread and I am so used to dividing it by factor when I use it, that I forgot.

I have updated the scripts in post 2.

:D
Author:  fx800 [ Sun Mar 03, 2013 3:12 pm ]
Post subject:  Re: Script for placing pending orders

The sell script is giving rise to error (4107) : invalid price parameter for trade function.

This may be caused by the sell script

price = xxx - SubtractFromLow - xxx, instead of price = xxx - SubtractFromLowPips - xxx,

because the code failed to make a call to extern int SubtractFromLowPips = xxx ?

A typo error ?

The buy script works just fine.

pete
All times are UTC Page 1 of 5