Conditional Buy after a Condition has been met

Questions about MultiCharts and user contributed studies.
haxen
Posts: 6
Joined: 06 Feb 2010
Has thanked: 2 times
Been thanked: 3 times

Conditional Buy after a Condition has been met

Postby haxen » 07 Feb 2010

Hello, I would like to enter a Buy Order once a momentum oscillator has hit the highest high of the past 3 days.

That is my trigger.

But I dont want to buy right after my trigger has been sent, I want to buy if the price retraces to the 20 period EMA within the next 20 bars.

Can i do this?

Can i Set:

Code: Select all

LongEntryPrice = xAverage(Price,20);
if MomentumOscillator = Highest(MomentumOscillator,3) then Buy next bars LongEntryPrice limit;
How do I restrict the Buy entry to be within only 20 bars of the trigger bar?

Much appreciated.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 07 Feb 2010

Here's the idea. (this is not the complete code, you have to fine tune it)

you have to add

1. a buy_ok condition to start the process
2. a bar counter and count for the next 20 bars.

3. reset the counter when the 20 bar limit is done.


HTH

Code: Select all

var:
buy_OK(false);

buy_ok = MomentumOscillator > Highest(MomentumOscillator,3);

if buy_ok and counter < 20 then
begin

counter = counter + 1;

Buy next bars LongEntryPrice limit;

end;

haxen
Posts: 6
Joined: 06 Feb 2010
Has thanked: 2 times
Been thanked: 3 times

Postby haxen » 07 Feb 2010

That is great. Thankyou.

Now, can i set the Buy Price to be equal to the ongoing calc of the 20 period EMA, not the EMA at the time of the trigger, but the ongoing EMA.

So after the trigger, if price ever comes back to meet the new 20 period ema, that is when i buy.

Is that possible??

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 07 Feb 2010

That is great. Thankyou.

Now, can i set the Buy Price to be equal to the ongoing calc of the 20 period EMA, not the EMA at the time of the trigger, but the ongoing EMA.

So after the trigger, if price ever comes back to meet the new 20 period ema, that is when i buy.

Is that possible??

that's a very fundamental programming question.
The answer is YES...

with EasyLanguage, you can program it to do almost anything you want;
if you can articulate the logic,
you can program it.


May I suggest you start here:
http://forum.tssupport.com/viewtopic.php?t=6929

haxen
Posts: 6
Joined: 06 Feb 2010
Has thanked: 2 times
Been thanked: 3 times

Postby haxen » 09 Feb 2010

I came up with setting a condition which sets a state flag and then used Currentbar plus a variable "numEntryBars" as a counter with a max on this sum as my cutoff for entering into the trade.

I also backshifted my 20 period lookback by 5 periods when looking to see that the current oscillator was not in a divergence but to allow for the event that it may not be the high point in the current peak.


Return to “MultiCharts”