Plot Lines on chart


#1

hello World

I havent written any code myself I want to try with codes available on the net

Please help

If the present signal is BUY

want to plot a line on "previous Sell signal"'s Lowest low and Highest high for Target and stop loss

and if the current signal is SELL then want a line plotted on Previous Buy signals Highest high and Lowest Low as sl and target

Can someone give an example or the code taking the SMA as an indicator like
if the SMA gives a buy signal then want to plot lines on "previous SMA Sell signal" s Highest High and Lowest Low as sl and Target.

I understand that on SMA target and sl wont mean a buy or sell ... I just want to plot The lines on the chart.

Thanks


#2

#3

Thanks @awilson
However that does not solve My issue

eg : I get a buy signal when there is a crossover
Now I want to Plot two Lines on the chart
I want the Lines to be plotted on Highest High and Lowest Low of the "PREVIOUS " Sell signals till the latest BUY signal ...

I want the Highest High and Lowest Low Plotted since the PREVIOUS Sell Signal

Please Help


#4

Welcome @twin. If you have not already read How do I learn AFL? and How do I debug my formula?, then that would be an Excellent place to start.

Working from someone else's code is a good start. Start small by making "obvious or simple changes" first to figure out how it all works.

Also for best results, post your code (properly using the code block "</>") and we can then give acutal specific corrections.

Last but not least, explain your request Clearly. In your current post, several things I don't understand, so perhaps a descriptive example.

Additionally, if you can figure out how to use the Exploration, you can track values if items that you want to use in your code, and make sure you are referencing them properly.


#5

@snoopy.pa30 I already broke my head on what you suggested and I failed .... spent a day to figure it out .... and failed so I asked for Help here


#6

@twin what parts "broke your head", and is it coding in general, or this specific case?

Your response to @awilson was better described, but try some code - in an exploration and see what numbers you get...

Show us the code (signal generation and plot lines that you want) and we can try it out and make suggestions.


#7

BS

@snoopy.pa30

Let say i get a buy signal and the up arrow pops up on the screen
After the Up arrow Pops up on the screen I want Two Lines plotted
Highest High Value since the PREVIOUS Sell Signal
and Lowest Low Value Since the Previous SELL signal

And do the same if a new sell signal pops up which should plot HH LL of Previous Buy Signal

Thank You


#8

#9

@PanoS Pls Look at the Post Replies just moving in circles


#10

@twin, You are getting suggestions from some major players (@awilson and @PanoS).

Have you looked at the example? Have you played with it.

Can you tell us exactly what does not work, or what is missing from your requirements.

Then have you searched the Manual for functions (Alphabetical list of AFL Functions and Categorized list of AFL Functions)? Searching and reading might lead you to the functions that would help you do what you want.

You will find that this board tends to help those who are trying to learn. i.e. They post their code (give credit to original coder is using someone's code to modify) and show where they are having difficulty.

My guess is that if you start with the link given and figure out how each line works, then spend a little time on the Help manual Function List, you can find functions that would help you do what you want. Then post your code (use code blocks) and have commented lines where you want the magic to occur... Then we will be more willing to help out.


#11

Indeed they are ... but I think the simplest issue is not understood ... brother I know what u r saying and i understand what there code which they post do ... however its not what i wanted .


#12
_SECTION_BEGIN("Triple EMA Crossover Rules");

P1 = ParamField("Price field",-1);
Periods1 = Param("Periods1", 3, 2, 300, 1, 10 );
Plot( EMA( P1, Periods1 ), _DEFAULT_NAME(), ParamColor( "Color1", colorCycle ), ParamStyle("Style1") ); 

P2 = ParamField("Price field",-1);
Periods2 = Param("Periods2", 13, 2, 300, 1, 10 );
Plot( EMA( P2, Periods2 ), _DEFAULT_NAME(), ParamColor( "Color2", colorCycle ), ParamStyle("Style2") ); 

P3 = ParamField("Price field",-1);
Periods3 = Param("Periods3", 34, 2, 300, 1, 10 );
Plot( EMA( P3, Periods3 ), _DEFAULT_NAME(), ParamColor( "Color3", colorCycle ), ParamStyle("Style3") ); 



Buy = EMA(P1, Periods1) > EMA(P2, Periods2) AND EMA(P2, Periods2) > EMA(P3, Periods3);
Sell = EMA(P1, Periods1) < EMA(P2, Periods2) AND EMA(P2, Periods2) < EMA(P3, Periods3);

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


Filter=Buy OR Sell;
SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar );
addcolumn( Close, "Close price", 1.4 );


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

_SECTION_END();

BS2

"considering the latest Sell signal"

When ever a signal appears BUY or SELL
want to plot Highest high and Lowest Low of previous BUY or SELL signal till the latest signal which appears....

@awilson @PanoS @snoopy.pa30

Pls Help ... Having a pain in the neck sitting and trying to fix


#13

Thanks for the code...

Have you looked at the HighestSInce() function?

Or the BarsSince() function?


#15

@twin, here is a small modification to your code.

Please note that I have both IMPULSE Signals and STATE Signals.

Changed the Exploration to show values and (hopefully) show problems.

DID NOT DO ANY PLOTTING

Let us know know it goes. And Finished working code is great for others to learn from....

P1 = ParamField("Price field",-1);
Periods1 = Param("Periods1", 3, 2, 300, 1, 10 );
Plot( EMA( P1, Periods1 ), _DEFAULT_NAME(), ParamColor( "Color1", colorCycle ), ParamStyle("Style1") ); 

P2 = ParamField("Price field",-1);
Periods2 = Param("Periods2", 13, 2, 300, 1, 10 );
Plot( EMA( P2, Periods2 ), _DEFAULT_NAME(), ParamColor( "Color2", colorCycle ), ParamStyle("Style2") ); 

P3 = ParamField("Price field",-1);
Periods3 = Param("Periods3", 34, 2, 300, 1, 10 );
Plot( EMA( P3, Periods3 ), _DEFAULT_NAME(), ParamColor( "Color3", colorCycle ), ParamStyle("Style3") ); 



Buy = EMA(P1, Periods1) > EMA(P2, Periods2) AND EMA(P2, Periods2) > EMA(P3, Periods3);
Sell = EMA(P1, Periods1) < EMA(P2, Periods2) AND EMA(P2, Periods2) < EMA(P3, Periods3);

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

CrossH = HighestSInce( Buy, H );
CrossL = HighestSInce( Buy, L );

//LineCrossH = IIf( HighestSInce( Buy ) , CrossH, Null );
//LineCrossL = IIf( HighestSInce( Buy ) , CrossL, Null );

Plot( CrossH, "CrossH", colorLightBlue, styleDashed | styleThick );
Plot( CrossL, "CrossL", colorRed, styleDashed | styleThick );


// Snoopy Changes START
// STATE Signals
statebuy = EMA(P1, Periods1) > EMA(P2, Periods2) AND EMA(P2, Periods2) > EMA(P3, Periods3);
statesell = EMA(P1, Periods1) < EMA(P2, Periods2) AND EMA(P2, Periods2) < EMA(P3, Periods3);
lookbackbuy = BarsSince(Buy);
lookbacksell = barssince(Sell);

Filter = 1;
AddColumn(C, "Close");
AddColumn(statebuy, "stateuy", 1.0);
AddColumn(statesell, "statesell", 1.0);
AddColumn(lookbackbuy, "Look Back Buy", 1.0);
AddColumn(lookbacksell, "Look Back Sell", 1.0);

/*
Filter=Buy OR Sell;
SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar );
addcolumn( Close, "Close price", 1.4 );
*/
// Snoopy Changes END
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

#16

I shall Work on it Thanks @snoopy.pa30


#18

Here is one plot solution to plot highest and lowest since previous sell between "Not in Trade"-zone (as always multiple roads lead to Rome):

/// dummy system
period = 20;
m = MA( Close, period );
Buy =  Cross( Close, m ); 
Sell = Cross( m, Close ); 

/// http://forum.amibroker.com/t/plot-lines-on-chart/5581/17
/// Plots the highest since previous Sell and lowest since previous Sell
/// code snippet by fxshrat@gmail.com
bi = BarIndex();
NotInTrade = Flip(Sell, Buy);
futlow = ValueWhen( Buy OR bi == LastValue(bi), Ref(LowestSince(Sell, L), -1), 0 );// looks into "future", don't use for BT!
ll = IIf( NotInTrade OR Ref(NotInTrade, -1), Valuewhen( Sell, futlow), Null );// looks into "future", don't use for BT!
futhigh = ValueWhen( NotInTrade, ValueWhen(Buy, Ref(HighestSince(Sell, H),-1), 0) );// looks into "future", don't use for BT!
hh = IIf( NotInTrade OR Ref(NotInTrade, -1), futhigh, Null );// looks into "future", don't use for BT!

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( HH, "\nHighest Since Previous Sell", colorRed, styleStaircase );
Plot( ll, "Lowest Since Previous Sell", colorGreen, styleStaircase );

Plot( C, "Price", colorGrey50, styleBar );
PlotShapes( Buy * shapeUpArrow, colorGreen, 0, L );
PlotShapes( Sell * shapeDownArrow, colorRed, 0, H );

111


#19

Thanks for the hlp @fxshrat
however not fixing what I Want,
I just want Lines Plotted for Previous Highest and Lowest of the previous Signal


#20

@fxshrat

You sent me this in Inbox

Look at your CHARt
http://forum.amibroker.com/uploads/default/original/2X/e/ecfc4bafb44df85229bc9cfb9bd9cca9d92a6981.jpg

My code does plot from highest since previous Sell till previous bar of "current" Buy.
As well as lowest since previous Sell till previous bar of "current" Buy.

Your chart is showing the same thing!

And here is your Text!!

Highest High Value since the PREVIOUS Sell Signal
and Lowest Low Value Since the Previous SELL signal

Stop wasting time of other people if you can't articulate properly!

_SECTION_BEGIN("Triple EMA Crossover Rules");

P1 = ParamField("Price field",-1);
Periods1 = Param("Periods1", 3, 2, 300, 1, 10 );
Plot( EMA( P1, Periods1 ), _DEFAULT_NAME(), ParamColor( "Color1", colorCycle ), ParamStyle("Style1") ); 

P2 = ParamField("Price field",-1);
Periods2 = Param("Periods2", 13, 2, 300, 1, 10 );
Plot( EMA( P2, Periods2 ), _DEFAULT_NAME(), ParamColor( "Color2", colorCycle ), ParamStyle("Style2") ); 

P3 = ParamField("Price field",-1);
Periods3 = Param("Periods3", 34, 2, 300, 1, 10 );
Plot( EMA( P3, Periods3 ), _DEFAULT_NAME(), ParamColor( "Color3", colorCycle ), ParamStyle("Style3") ); 



Buy = EMA(P1, Periods1) > EMA(P2, Periods2) AND EMA(P2, Periods2) > EMA(P3, Periods3);
Sell = EMA(P1, Periods1) < EMA(P2, Periods2) AND EMA(P2, Periods2) < EMA(P3, Periods3);

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


Filter=Buy OR Sell;
SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar );
addcolumn( Close, "Close price", 1.4 );


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

_SECTION_END();



/// dummy system
period = 20;
m = MA( Close, period );
Buy =  Cross( Close, m ); 
Sell = Cross( m, Close ); 

/// http://forum.amibroker.com/t/plot-lines-on-chart/5581/17
/// Plots the highest since previous Sell and lowest since previous Sell
/// code snippet by fxshrat@gmail.com
bi = BarIndex();
NotInTrade = Flip(Sell, Buy);
futlow = ValueWhen( Buy OR bi == LastValue(bi), Ref(LowestSince(Sell, L), -1), 0 );// looks into "future", don't use for BT!
ll = IIf( NotInTrade OR Ref(NotInTrade, -1), Valuewhen( Sell, futlow), Null );// looks into "future", don't use for BT!
futhigh = ValueWhen( NotInTrade, ValueWhen(Buy, Ref(HighestSince(Sell, H),-1), 0) );// looks into "future", don't use for BT!
hh = IIf( NotInTrade OR Ref(NotInTrade, -1), futhigh, Null );// looks into "future", don't use for BT!

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( HH, "\nHighest Since Previous Sell", colorRed, styleStaircase );
Plot( ll, "Lowest Since Previous Sell", colorGreen, styleStaircase );

Plot( C, "Price", colorGrey50, styleBar );
PlotShapes( Buy * shapeUpArrow, colorGreen, 0, L );
PlotShapes( Sell * shapeDownArrow, colorRed, 0, H );

Here is my code with your Code

BS3

@fxshrat do you see where is the previous high of the present signal is?


#21

:roll_eyes: Oh boy... just like I said... another waste of time...

Do you actually understand that you are mixing TWO DIFFERENT SYSTEM CODES!!
You are mixing my dummy signal code with your EMA signal code. You should remove my dummy system's signals code since it overrides your buy sell variables. Do you understand the purpose of examples (dummy signals)??

Again stop wasting other peoples time if you don't understand what you are doing there!

My code snippet does exactly what you were looking for.
It plots Lowest and Highest since previous Sell till previous bar of "current" Buy!

This is your text

Highest High Value since the PREVIOUS Sell Signal
and Lowest Low Value Since the Previous SELL signal

read loudly and clearly

And this is your picture again http://forum.amibroker.com/uploads/default/original/2X/e/ecfc4bafb44df85229bc9cfb9bd9cca9d92a6981.jpg

And here is picture of using my code snippet with your EMA signals (but WITHOUT my dummy MA code).

03

Another hint: Don't argue with oldtimers having more clue. And don't expect another spoon feeding.


#22

@fxshrat Brother I not arguing , I dont know how to code and sitting here asking for help everyone giving advice and suggestion not a clear picture of the code. The code you gave dint work for me removed your dummy code ... but I might be doing it wrong