Simple Coding Help - No Promise.

Hi All,

Its great to see people helping each other and learning on the way :) Great initiative .

I am new to trading and hence the thread gives me great chance to learn . over the past week or so I tried to read as much as possible about Indicators and Moving averages . I would like to sum up a few things here ( please do let me know if I am wrong in my assumptions ) .

Note : I am NOT a intraday trader . So I cant think from that perspective . I do my analysis only EOD .

So I while designing a trading system I need to take care of the following :

a )
Stochastic :
Buy=Cross(StochK(),StochD())
Sell = ?

b ) [Positive/Negative] Directional Movement Indicator :

Buy = Cross(PDI(),MDI())
Sell = ?

c ) ADX :

ADX > 25 : uptrend
ADX > 50 : strong uptrend
ADX < 25 : downtrend

Buy : ADX > 25
Sell : ADX < 25

d ) Moving Average Convergence Divergence

Buy = MACD()>Signal() AND (ADX()>25)
Sell = Cross(Signal(),MACD())



Questions :

1 . As you can see I have fairly good entry signals but I still am unable to define good exit signals . I read that its not good to involve alot of indicators in a single system . Here i involve alot ( MACD , ADX , Stochastic , ) I am yet to involve RSI .

So is it a good idea to involve so many constructs all at once ? I have tried backfiling with average to OK results .

2 . Also can someone help me define my SELL signals better ? Like how do they use the above constructs to exit trades ( or their combinations )

Much thanks .
 

nac

Well-Known Member
This is more like a question than a request for a code.

Is this possible to calculate days between the signals (Signal in the sense, when the said conditions are met, like BUY, SELL etc.,) by coding an afl?

For eg: We take the last afl I asked here.

TOUCH20 = H > EMA(C,20) AND L < EMA(C,20);
FILTER = TOUCH20;
ADDCOLUMN (TOUCH20,"TOUCH20");

Let's assume that price touched ema20 last on Apr 20th, before that it was 18th Apr. Now I want the exploration to calculate the days between those two dates, i.e. 20 apr minus 18 apr.
Like that it should calculate the days between (lets assume there were 20 occurrence),
occurrence 20 and occurrence 19;
occurrence 19 and occurrence 18;
occurrence 18 and occurrence 17.......
........

I googled and tried lastvalue, but that's nowhere close to what I am expecting.

Is this simple to code or is it better to export the data and calculate the difference in excel?
 

trash

Well-Known Member
This is more like a question than a request for a code.

Is this possible to calculate days between the signals (Signal in the sense, when the said conditions are met, like BUY, SELL etc.,) by coding an afl?

For eg: We take the last afl I asked here.

TOUCH20 = H > EMA(C,20) AND L < EMA(C,20);
FILTER = TOUCH20;
ADDCOLUMN (TOUCH20,"TOUCH20");

Let's assume that price touched ema20 last on Apr 20th, before that it was 18th Apr. Now I want the exploration to calculate the days between those two dates, i.e. 20 apr minus 18 apr.
Like that it should calculate the days between (lets assume there were 20 occurrence),
occurrence 20 and occurrence 19;
occurrence 19 and occurrence 18;
occurrence 18 and occurrence 17.......
........

I googled and tried lastvalue, but that's nowhere close to what I am expecting.

Is this simple to code or is it better to export the data and calculate the difference in excel?
Why making it complicated by using Excel if it is simple using just one line?

This one is for counting bars of any TF
Code:
bi = barindex();
diff = ValueWhen( touch20, bi ) - ValueWhen( touch20, bi, 2 );
or

counting days (part of DB) between intraday occurrences by using barindex
Code:
TimeframeSet( inDaily );
bi = barindex();
TimeframeRestore();

bi = TimeFrameExpand( bi, inDaily, expandmode = expandFirst );

diff = ValueWhen( touch20, bi ) - ValueWhen( touch20, bi, 2 );
If you want to count days including those ones having no bars in the DB then use dayofyear() instead of Barindex. Care should be taken if there is new year start. For that you need to adjust the code.
 
Last edited:

trash

Well-Known Member
If you want to count days including those ones having no bars in the DB then use dayofyear() instead of Barindex. Care should be taken if there is new year start. For that you need to adjust the code.
Well, instead of DayofYear() use DaysSince1900() function. Then it will also work for new year changes.

Code:
dd = DaysSince1900(); 
diff = ValueWhen( touch20, dd ) - ValueWhen( touch20, dd, 2 );
 

xsis

Active Member
does it work only on the BUY side? even when the price breaks the LOW, it doesn't generate any SELL signal!!
as on various symbols i only found BUY signal getting triggered?

Code:
 NewDay = Day()!= Ref(Day(), -1);
 afterbreakout0 = Cross(TimeNum(),093000);
 afterbreakout1 = TimeNum()>= 093000 AND TimeNum()<=151500;
 highestoftheday = HighestSince(newday,H,1);
 Lowestoftheday =LowestSince(newday,L,1);
 ORBHigh = ValueWhen(afterbreakout0,highestoftheday,1);
 ORBLow = ValueWhen(afterbreakout0,lowestoftheday,1);
 Buy= Cross(C,orbhigh) AND afterbreakout1;
 Sell = Cross(orblow,C) AND afterbreakout1 OR Cross(TimeNum(),151500);

 Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);


Short=Cross(ORblow,C) AND afterbreakout1;
Cover=Cross(C,ORbhigh) AND afterbreakout1  OR Cross(TimeNum(),151500);

Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


 Plot(C,"",colorYellow,styleBar);
 PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
 PlotShapes( shapeDownArrow * Sell, colorRed,0,H,-12);
 Plot(afterbreakout0,"",colorBlue,styleHistogram|styleOwnScale);
 Plot(ORBHigh,"",colorGreen,styleDots);
 Plot(ORBLow,"",colorRed,styleDots);
Found this very old file, this will take all trades, me thinks . . . .

Adjust the BO time as your requirements . . .


Happy :)
 
does it work only on the BUY side? even when the price breaks the LOW, it doesn't generate any SELL signal!!
as on various symbols i only found BUY signal getting triggered?
Change the 2 Plotshapes lines with this . . .

Code:
 PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
 PlotShapes( shapeDownArrow * Short, colorRed,0,H,-12);
 PlotShapes( shapeHollowUpArrow * Cover, colorGreen,0,L,-12);
 PlotShapes( shapeHollowDownArrow * Sell, colorRed,0,H,-12);

Happy :)
 

amitrandive

Well-Known Member
Hi All,

Its great to see people helping each other and learning on the way :) Great initiative .

I am new to trading and hence the thread gives me great chance to learn . over the past week or so I tried to read as much as possible about Indicators and Moving averages . I would like to sum up a few things here ( please do let me know if I am wrong in my assumptions ) .

Note : I am NOT a intraday trader . So I cant think from that perspective . I do my analysis only EOD .

.
.
.
.

Questions :

1 . As you can see I have fairly good entry signals but I still am unable to define good exit signals . I read that its not good to involve alot of indicators in a single system . Here i involve alot ( MACD , ADX , Stochastic , ) I am yet to involve RSI .

So is it a good idea to involve so many constructs all at once ? I have tried backfiling with average to OK results . Do not do so , too many cooks spoil a meal .Similarly too many indicators leads to analysis paralysis.

2 . Also can someone help me define my SELL signals better ? Like how do they use the above constructs to exit trades ( or their combinations )
Posted a link and image for the same.
Much thanks .
I have posted an image and a link for you.You may want to explore that and design your own system.

http://forex-strategies-revealed.com/advanced/system-selection-technique

 
Hi,

Can any one help me with how to write a code for the following logic.

1. I want a indicator which oscillates between 1 to -1.
2. "1" should be the hhv of all the bars in the stock.
3. the period for the range 1 to -1 should be controlled by a parameter (default 365, range from 50 to 1000).

Please let me know,
Thank you,
Hema.
 

Similar threads