Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 21:48:21 +0000



[Programming Help] - coding question

View Count: 1214

[2018-03-01 18:50:05]
Glenn Infinity - Posts: 103
Do you know why the coding below would initiate another trade while it was still above the band? Can a condition be put on the code to prevent another trade until it satisfies the 2nd condition?

I am taking a long when the price closes outside the bollinger band and short when it closes below the bollinger band.

I want the code to be take one long trade not multiple long trades until it changes direction i.e. goes back in the band.

Here is the simple alert condition code:

Long: C>ID2.SG1
Short: C<ID2.SG3

Where ID2.SG1 is the upper band and ID2.SG3 is the lower band

Thanks,
[2018-03-01 23:55:53]
Sawtooth - Posts: 3993
Try this:
Long: AND(C[-1]<ID2.SG1[-1],C>ID2.SG1)
Short: AND(C[-1]>ID2.SG3[-1],C<ID2.SG3)
[2018-03-04 11:27:17]
User924725 - Posts: 26
hello @tomgilb

any ideas on how we can expand the alert you gave with one more condition?
i use kelnter bands so the above code is similar

what i would like to add to the above code is taking a (long described on the conditions you gave) ONLY when upper kelnter band is pointing up.
with this way we eliminate signals taken when ketner bands are flat(RANGE MARKET) or moving down(DOWNTREND).

I tested the code you gave above. On an UPTREND is working well for a small profit BUT when we are in RANGE-Consolidation then false signals taking place.
So if we could also add the condition i asked above with the keltners the false signals are eliminating.

A good addition to eliminate more false signals would be to add a condition for a MOVING AVERAGE Based on slope. AND also set a stop for Longs taken at lower keltner and a fixed target for exit with limit order.

See below the image to give you a better idea
Keltner banks are with blue
Moving Average is yellow

AM I ASKING TOO MUCH?? :)
imagetrading system.png / V - Attached On 2018-03-04 11:19:04 UTC - Size: 142.65 KB - 348 views
[2018-03-04 14:24:49]
Sawtooth - Posts: 3993
AM I ASKING TOO MUCH?? :)
You'll need to objectively define 'flat'.
You could use the Study Angle study to do that.
You'll need an instance of it for each line.
[2018-03-04 16:08:44]
User924725 - Posts: 26
Yes i understand what you say ,

the problem for me is more that if i write each alert code individually then i dont know how to put them all together

example of a LONG alert
CODE TO TAKE THE LONG IF CLOSING ABOVE UPPER KELTNER + CODE FOR TAKE THE LONG ONLY IF UPPER KELTNER IS POINTING UP + CODE FOR TAKE THE LONG ONLY IF MOVING AVERAGE IS SLOPING UP
all those condition must be true.

and then take this alert and put it on a trading system study with a stop on lower keltner and a fixed target based on ATR .

thanks for pointing out anyway :)
[2018-03-04 17:40:33]
Sawtooth - Posts: 3993
The conditions are actually this:
-Long when C crosses above upper Keltner (not just above)
and
-Keltner is upsloped
and
-MA is upsloped

The entire Longs code looks like this =AND(CxoK,Kup,MAup)
The crossover portion is in post#2:
AND(C[-1]<ID2.SG1[-1],C>ID2.SG1)
The Kup portion is this, where the current is > the previous:
ID2.SG1>ID2.SG1[-1]
The MAup portion is this (where the MA is ID1, edit as needed, and the current is > the previous):
ID1.SG1>ID1.SG1[-1]

Put it together:
=AND(C[-1]<ID2.SG1[-1],C>ID2.SG1,ID2.SG1>ID2.SG1[-1],ID1.SG1>ID1.SG1[-1])
[2018-03-04 18:15:57]
User924725 - Posts: 26
YOU ARE AWESOME THANKS!!!!

the more valuable thing is that you tought me the way of thinking that will help to code and other alerts
Date Time Of Last Edit: 2018-03-04 18:24:21

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account