Simple Coding Help - No Promise.

Hi,

Happy New Year to all of you and your family .

I have recently joined this group and finding this thread a great start to learn afl coding. I have just learn to code simple cross overs. Can some one help to code the following.


Buy Conditions:

1. close price should be above 20 Ema.
2. Buy signal to be generated only if price is also above 100 Ema and 20 Ema is also above 100 Ema.
3. Buy to be 15 points above the high of the buy candles. ( I mean the buy will trigger in subsequent candles only when the high of the buy candle is broken.
4. While Ema 20 and price is above 100 ema, only buy above 20 ema and exit or sell the longs below 20 ema. No fresh shorts. Fresh shorts are only on the below sell conditions.
5. Exits ( Sell the Longs) will be when the price closes below 20 Ema and the low need to be broken in the subsequent candle. No further short trades.
6. While the price and Ema 20 stays above 100 ema fresh buy entry can be taken once again when price passes above 20 Ema and the high is broken with few points.

Sell Condition.

1. close price should be below 20 Ema.
2. Short signal to be generated only if price is also below 100 Ema and 20 Ema is also below 100 Ema.
3. Short to be 15 points below the low of the short candle. ( I mean the sell will trigger in subsequent candles only when the low of the short candle is broken.
4. While Ema 20 and price is below 100 ema, only short below 20 ema and cover above the 20 ema. No fresh longs. Longs are only on the above buy conditions.
5. Cover (Exit) will be when the price closes above 20 Ema and the high need to be broken in the subsequent candle.
6. While the price and Ema 20 stays below 100 ema fresh short entry can be taken once again when price goes below 20 Ema and the low is broken with few points.

I just wanted to back test and forward test this and see the result and take for live trades then based on the results.

Idea here is that I wanted to assume that as long as the price and the 20 ema are above 100 ema, only longs need to be entered and exit the longs. Viceversa for shorts.

Buy price is few points above the high of the buy candle.
Sell Price is few points below the low of the sell candle.

Shortprice is few points below the low of the short candle.
Cover price is few points above the high of the cover candle.

No trades when price is between 20 ema and 100 ema. Even if price closes above 20 ema but if 20 ema is lower than 00 ema no longs and vice versa for short trades.

Sorry to take your time.

Please ignore if this is going to disturb your time.
 

Nehal_s143

Well-Known Member
Sorry sir, I dont deserve credit for this work

Credit goes to you, Happy Sir & Pratap Sir :thumb:, I have just re-posted the solution mentioned in some old post of this thread



Good Work, Nehal!

Only a small improvement; Its better to use comparison in line with Param Toggle like this

if (ParamToggle("SNR","NONE|YES",1) == 1)

OR

if (ParamToggle("SNR","NONE|YES",1) == 0)

Another AFL function that can be used to turn On or turn Off anything selectively is ParamList where the selected choice is returned as string and you have to compare result with strings.
 

Nehal_s143

Well-Known Member
helo all can any one help me that what is stop loss line gray colour in www.livesi
gnal.in pls post reply
Looks like super trend with some moving pivot,

super trend afl code

_SECTION_BEGIN("Super Trend");
period = Param("Period", 10, 1, 240, 1);
mult = Param("Multiplier", 3, 1, 240, 0.1);

f=ATR(period);

VS[0] = Close[0];
trend[0] = 0;
HighC[0]=0;
Lowc[0]=0;

for( i = period+1; i < BarCount; i++ )
{

vs = vs[i-1];
trend = trend[i-1];
highC = HighC[i-1];
lowc = lowc[i-1];

if ((trend>=0) && ( C <VS ))
{
trend =-1;
HighC = C;
lowc = C;
}

if ((trend<=0) && (C >VS))
{
trend=1;
HighC = C;
lowc = C;
}

if (trend==-1)
{
if (C<lowc) lowc = C;
VS= lowc+ (mult*f);
}


if (trend==1)
{
if (C>HighC) HighC = C;
VS= HighC-(mult*f);
}

}


Buy=Cross(Trend,0);
Sell=Cross(0, Trend);

Plot(Close,"Close",colorBlue,styleCandle);
Plot(VS, "Vol Stop",IIf(trend==1,10,11 ),styleThick);

mkol = IIf( Trend==1, 10, 11);
//Plot(5, "ribbon", mkol, styleOwnScale|styleArea|styleNoLabel, 0, -5); // Weekly trend

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low-f, High+f));
_SECTION_END();

_SECTION_BEGIN("Adaptive price channel");
//Adaptive price channel

//SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

//Plot(C,"",colorBlack,styleCandle);

Lookback=20;
MaxLookback=Param("Max Lookback period",40,20,60,5);
MinLookback=Param("Min Lookback period",20,10,20,5);

Vol=StDev(C,30);
Change=(Vol-Ref(Vol,-1))/Ref(Vol,-1);

StartBar = BeginValue( BarIndex() ); ;
FinishBar = EndValue( BarIndex() );

i = StartBar;

for (i = StartBar+31; i<Finishbar; i++)
{

Lookback=round(Lookback[i-1]*(1+Change));

if(Lookback>MaxLookback)
{
Lookback=MaxLookback;
}

if(Lookback<MinLookback)
{
Lookback=MinLookback;
}

}

HighChannel=Ref(HHV(H,Lookback),-1);
LowChannel=Ref(LLV(L,Lookback),-1);

Plot(HighChannel,"",colorPink,styleThick | styleNoRescale);
Plot(LowChannel,"",colorSeaGreen,styleThick | styleNoRescale );

GraphXSpace=7;
_SECTION_END();
 

mastermind007

Well-Known Member
ur code is not der...though i had tried that...

I have shown you the afl. to get you an idea what i want..
So, you've been wasting my time.

Sorry, I will not be involved in your efforts anymore.
 

amitrandive

Well-Known Member
seems 200ema but many time it wil give wishpaw u can try
Jitensingh

I think your question was , " What is the grey line?"

My answer is " It seems to be 200EMA" .

I know 200 EMA will give many whipsaws , that is why the site address you posted will show you screen shots of only hugely successful trades only:D:D:D
 

mehtaka

Active Member
So, you've been wasting my time.

Sorry, I will not be involved in your efforts anymore.
sorry mastermind,
but your time and efforts are definitely not wasted.
I posted my afl so that you u can know what exactly wanted.
I did put your code but couldnt find from where i can change the dates...
as i had mentioned earlier, that different commodities have different expiry.

Thats y i tried coding my self and shown to you, so that may be from der you may be able to get the clue what i am looking for.

Your work is and always appreciated.
 

Similar threads