Why i=0; is not a numeric in afl

MSN1979

Well-Known Member
#21
Hi MSN, is this code meant for Long trades (BUY) only? Is there a different rule for Short trades (SELL). What about Target and Stoploss ? I am asking because I am trying to refine the code.

-Anant

Yes, I wrote the code for long. It works on all Time Frames. Short will be very easy to write, but problem is I am unable to control in real time.

Few things that came to my notice.

1. Chart's first bar high shows correctly in GFX print, but when you use explore it shows it incorrectly. I don't know why.

2. If you scroll the chart in 1 min time frame it forgets opening bar value and then it will start printing 0.

3. Now I can compare the candles but trades keep executing if the breakout has already happened. Tried EXREM function


Now replying to your questions.

SL is opening candle Low.

My personal opinion is to book partial profit at Fix 20 P for nifty

Rest must be left for 3:15 or until it hits opening candle low

Instead of 20 P I would also like to test this, We can also check the trend on same Time frame, if its making Higher High and Higher Low Pivots keep trailing with pivot low, we can ignore inside pivots.

For outside bars we consider them as part of the trend in the direction of the move. We must exit on outside bars also.

Inside bars we dont take any action, neither we move sl or trail

Yes same rule for Sell, break of 15 min candle low / or any chart time frame low should be sell ( it should be less then daily time frame)
 
Last edited:

asnavale

Well-Known Member
#22
OK, understood your strategy. Let me try to code it. I have partially coded a system based on OB range. I will tweek it to suit your strategy.

-Anant
 

MSN1979

Well-Known Member
#23
OK, understood your strategy. Let me try to code it. I have partially coded a system based on OB range. I will tweek it to suit your strategy.

-Anant

Anant Sir , I am trying to learn AFL :D . I wanted to buy original version of Amibroker. It would be great if someone can help me with logic part.
 

asnavale

Well-Known Member
#24
Yes, I wrote the code for long. It works on all Time Frames. Short will be very easy to write, but problem is I am unable to control in real time.

Few things that came to my notice.

1. Chart's first bar high shows correctly in GFX print, but when you use explore it shows it incorrectly. I don't know why.

2. If you scroll the chart in 1 min time frame it forgets opening bar value and then it will start printing 0.

3. Now I can compare the candles but trades keep executing if the breakout has already happened. Tried EXREM function
.
.
.
.
.
In your code there is no timeframe setting to 15mins. If you are seeing chart in 15 min timeframe, the code works properly. In any other time frame it may show wrong results. To get exploration correctly, you need to select proper values in exploration settings. Let me first finish the coding and then I will explain these things.

-Anant
 

asnavale

Well-Known Member
#25
Hi MSN,

Try the following Code. This shows only Long side break out. Works on all timeframes. Opening Bar High and Low are for 15minute candle irrespective of timeframe used. The trade is shown only after the breakout candle closes in timeframe selected for the chart display. As soon as the first breakout bar is found, its high and trade price are locked. Any candle breaking OBR high later is not considered. Target and Stoploss are not included in the AFL code. Exploration is not included. If the chart is as per your expectation, we can include the other features and exploration later.

For any changes post your requirement here.


C-like:
_SECTION_BEGIN("MSNOBR");

SetChartOptions(0, chartShowDates | chartWrapTitle);
SetBarsRequired(sbrAll);

TextX = Param("Text Horizontal Position", 400, 200, 1000, 10);
TextY = Param("Text Vertical Position", 50, 10, 1000, 10);
FontSize = Param("Font Size", 11, 8, 36, 1);

GfxSelectFont("Arial", FontSize);
GfxSetTextColor(colorWhite);
GfxSetBkColor(colorBlue);
GfxSelectPen(colorYellow);
GfxSetTextAlign(2);
GfxSelectSolidBrush(colorBlue);

NewDay = Day() != Ref(Day(), -1);

H15 = ValueWhen(NewDay, TimeFrameGetPrice("H", in15Minute));
L15 = ValueWhen(NewDay, TimeFrameGetPrice("L", in15Minute));
BI = ValueWhen(NewDay, BarIndex(), 1);

GfxRectangle(TextX + 20, TextY - 10, TextX - 360, TextY + 120);
GfxTextOut("Opening Bar High: " + StrFormat("%1.2f", LastValue(H15)), TextX, TextY);
GfxTextOut("Opening Bar Low : " + StrFormat("%1.2f", LastValue(L15)), TextX, TextY + 30);


for(i = LastValue(BI); i < BarCount - 1; i++)
    {
        GfxTextOut( "Waiting for Breakout ", Textx, Texty + 60);
        if (H[i] > H15[i])
            {
                GfxTextOut( "Breakout Bar High is: " + StrFormat("%1.2f", H[i]), Textx, Texty + 60);
                GfxTextOut( "Your Trade is Executed @ " + StrFormat("%1.2f", H[i]), Textx, Texty + 90);
                Break;
            }
    }   


_N(Title = StrFormat("{{NAME}}({{INTERVAL}}), {{DATE}}; {{OHLCX}}, Vol %1.0f; {{VALUES}}", V));

Plot(C, "", colorLightGrey, styleCandle);
Plot(H15,"H15", colorYellow, styleLine);
Plot(L15, "L15", colorOrange, styleLine);

_SECTION_END();

-Anant
 

MSN1979

Well-Known Member
#26
Hi MSN,

Try the following Code. This shows only Long side break out. Works on all timeframes. Opening Bar High and Low are for 15minute candle irrespective of timeframe used. The trade is shown only after the breakout candle closes in timeframe selected for the chart display. As soon as the first breakout bar is found, its high and trade price are locked. Any candle breaking OBR high later is not considered. Target and Stoploss are not included in the AFL code. Exploration is not included. If the chart is as per your expectation, we can include the other features and exploration later.

For any changes post your requirement here.


C-like:
_SECTION_BEGIN("MSNOBR");

SetChartOptions(0, chartShowDates | chartWrapTitle);
SetBarsRequired(sbrAll);

TextX = Param("Text Horizontal Position", 400, 200, 1000, 10);
TextY = Param("Text Vertical Position", 50, 10, 1000, 10);
FontSize = Param("Font Size", 11, 8, 36, 1);

GfxSelectFont("Arial", FontSize);
GfxSetTextColor(colorWhite);
GfxSetBkColor(colorBlue);
GfxSelectPen(colorYellow);
GfxSetTextAlign(2);
GfxSelectSolidBrush(colorBlue);

NewDay = Day() != Ref(Day(), -1);

H15 = ValueWhen(NewDay, TimeFrameGetPrice("H", in15Minute));
L15 = ValueWhen(NewDay, TimeFrameGetPrice("L", in15Minute));
BI = ValueWhen(NewDay, BarIndex(), 1);

GfxRectangle(TextX + 20, TextY - 10, TextX - 360, TextY + 120);
GfxTextOut("Opening Bar High: " + StrFormat("%1.2f", LastValue(H15)), TextX, TextY);
GfxTextOut("Opening Bar Low : " + StrFormat("%1.2f", LastValue(L15)), TextX, TextY + 30);


for(i = LastValue(BI); i < BarCount - 1; i++)
    {
        GfxTextOut( "Waiting for Breakout ", Textx, Texty + 60);
        if (H[i] > H15[i])
            {
                GfxTextOut( "Breakout Bar High is: " + StrFormat("%1.2f", H[i]), Textx, Texty + 60);
                GfxTextOut( "Your Trade is Executed @ " + StrFormat("%1.2f", H[i]), Textx, Texty + 90);
                Break;
            }
    }  


_N(Title = StrFormat("{{NAME}}({{INTERVAL}}), {{DATE}}; {{OHLCX}}, Vol %1.0f; {{VALUES}}", V));

Plot(C, "", colorLightGrey, styleCandle);
Plot(H15,"H15", colorYellow, styleLine);
Plot(L15, "L15", colorOrange, styleLine);

_SECTION_END();

-Anant

Thank you Anant, I was trying to learn AFL, You basically are spoon feeding me :). But thank you for the AFL. As a Beginner my objective was to learn and write few lines of code and take it from there on.

I will look at the AFL and Try to write commentary on how it works. This is simply great! You saved a lot of time and effort.

I see you have used Bar Index as BI, Not much is available in help file about BarIndex, But your code will give me a fair idea on how it works.

Thanx a MIL
 

MSN1979

Well-Known Member
#27
To predict is for slaves. To react is for kings!
Do not predict what prices are going to do. React to what prices are doing.

Don't bother about risk/reward ratio. Take what the market gives you.


PS: Simply Love your signature
 

MSN1979

Well-Known Member
#28
Test Result 1: Breakout on 15 min Triggered but Code is still waiting for breakout. Am I missing something?
1562645372106.png
 

asnavale

Well-Known Member
#29
As I have explained in my post, the breakout message appears only after the candle is complete. That means only after the candle is fully formed. In the chart you posted it is the second candle of the day in 15 min timeframe. Therefore, after 9:45 it will show the break out message. Just change the chart time to 5minutes and the message appears as soon as the 5minute candle is completed.

-Anant
 

asnavale

Well-Known Member
#30
By the way as per my data, NIFTY did not break 15 minute Opening Bar High so far. See the image attached here.

NIFTY.PNG



-Anant
 

Similar threads