Script for placing pending orders

User avatar
Sgt.Forex
Trader
Posts: 55
Joined: Wed Nov 16, 2011 11:03 am
Location: Germany

Script for placing pending orders

Post by Sgt.Forex »

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
Money makes the world go round! ;)
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Script for placing pending orders

Post by SteveHopwood »

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
You do not have the required permissions to view the files attached to this post.
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
Sgt.Forex
Trader
Posts: 55
Joined: Wed Nov 16, 2011 11:03 am
Location: Germany

Re: Script for placing pending orders

Post by Sgt.Forex »

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
Money makes the world go round! ;)
User avatar
Sgt.Forex
Trader
Posts: 55
Joined: Wed Nov 16, 2011 11:03 am
Location: Germany

Re: Script for placing pending orders

Post by Sgt.Forex »

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
Money makes the world go round! ;)
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Script for placing pending orders

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
Sgt.Forex
Trader
Posts: 55
Joined: Wed Nov 16, 2011 11:03 am
Location: Germany

Re: Script for placing pending orders

Post by Sgt.Forex »

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

Cheers
Money makes the world go round! ;)
User avatar
Sgt.Forex
Trader
Posts: 55
Joined: Wed Nov 16, 2011 11:03 am
Location: Germany

Re: Script for placing pending orders

Post by Sgt.Forex »

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
Money makes the world go round! ;)
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Script for placing pending orders

Post by fx800 »

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
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Script for placing pending orders

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Script for placing pending orders

Post by fx800 »

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
Post Reply

Return to “Scripts”