Contribute

Contribute an indicator to the library by clicking here. Note you must be logged in.

New! Stock Portfolio Organizer is now available:
  • Shares, Margin, Futures and Forex
  • EOD and Realtime data
  • And Much More...
GoTo Stock Portfolio Organizer
New! WiseTrader Toolbox for Amibroker is now available with:
  • Advanced Adaptive Indicators
  • Advanced Pattern Exploration
  • Neural Networks
  • And Much More...
GoTo WiseTrader Toolbox

Popular Indicators

TWAP for Amibroker (AFL)

3 / 5 (Votes 2)

Hi all, this is an attempt to do twap indicator. Please correct me if I’m wrong,,,

Similar Formulas

Formula

10 Comments

how to trade

this indicator for learning purpose please don’t use it as a trading indicator,the time weighted average price. is theaverage of OHLC prices for all previous bars to indicate a resistance of intraday trading. its just an attempt to start i welcome your comment,,,,

Hallo Mr Tradinology
First of all I would like to Thank You for your TWAP AFL. It’s a good idea.
When I create the line TWAP_5 and line TWAP_10, how to add an arrow signal to the intersection of the two lines.
I’ve tried several times but failed.
Thanks in advance Mr Tradinology

_SECTION_BEGIN("TWAP 5");
Bars_so_far_today = 5 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 090000, BarIndex());
TodayClose = Sum(C,Bars_so_far_today);
TodayHigh = Sum(H,Bars_so_far_today);
TodayLow = Sum(L,Bars_so_far_today);
TodayOpen = Sum(O,Bars_so_far_today);
TWAP_5 = (TodayClose + TodayHigh + TodayLow + TodayOpen)/4 ;
IIf (BarIndex() >= StartBar, ATWAP_5 = TWAP_5 / Bars_so_far_today,0);
ATWAP_5_Color = IIf(ATWAP_5 >= Ref(ATWAP_5,-1),colorYellow,colorBrown);
Plot(ATWAP_5,"",ATWAP_5_Color, styleline+styleThick|styleNoLabel,Null, Null, 0, 1, 2);
_SECTION_END();

_SECTION_BEGIN("TWAP 10");
Bars_so_far_today = 10 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 090000, BarIndex());
TodayClose = Sum(C,Bars_so_far_today);
TodayHigh = Sum(H,Bars_so_far_today);
TodayLow = Sum(L,Bars_so_far_today);
TodayOpen = Sum(O,Bars_so_far_today);
TWAP_10 = (TodayClose + TodayHigh + TodayLow + TodayOpen)/4 ;
IIf (BarIndex() >= StartBar, ATWAP_10 = TWAP_10 / Bars_so_far_today,0);
ATWAP_10_Color = IIf(ATWAP_10 >= Ref(ATWAP_10,-1),colorYellow,colorBrown);
Plot(ATWAP_10,"",ATWAP_10_Color, styleline+styleThick|styleNoLabel,Null, Null, 0, 1, 2);
_SECTION_END();

BUY_5_10 = Cross(TWAP_5,TWAP_10);
SELL_5_10 = Cross(TWAP_10,TWAP_5);
PlotShapes(IIf(BUY_5_10, shapeUpArrow, shapeNone),colorCustom12, 0,L, Offset=-20);               
PlotShapes(IIf(SELL_5_10, shapeDownArrow, shapeNone),colorCustom11, 0,H, Offset=20);

Dear bambanghk, unfortunately I’m new with afl. but i hope our friends here can contribute for solution,

OK Thank you Mr Tradinology
Please anyone can help ?

Hello bambanghk,
the problem is in

BUY_5_10 = Cross(TWAP_5,TWAP_10);
SELL_5_10 = Cross(TWAP_10,TWAP_5);

you should be using the arrays ATWAP_10 and ATWAP_5
the below code worked for me :

_SECTION_BEGIN("TWAP 5");
Bars_so_far_today5 = 5 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 090000, BarIndex());
TodayClose = Sum(C,Bars_so_far_today5);
TodayHigh = Sum(H,Bars_so_far_today5);
TodayLow = Sum(L,Bars_so_far_today5);
TodayOpen = Sum(O,Bars_so_far_today5);
TWAP_5 = (TodayClose + TodayHigh + TodayLow + TodayOpen)/4 ;
IIf (BarIndex() >= StartBar, ATWAP_5 = TWAP_5 / Bars_so_far_today5,0);
ATWAP_5_Color = IIf(ATWAP_5 >= Ref(ATWAP_5,-1),colorBlue,colorBrown);
Plot(ATWAP_5,"",ATWAP_5_Color, styleline+styleThick|styleNoLabel,Null, Null, 0, 1, 2);

Bars_so_far_today10 = 10 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 090000, BarIndex());
TodayClose = Sum(C,Bars_so_far_today10);
TodayHigh = Sum(H,Bars_so_far_today10);
TodayLow = Sum(L,Bars_so_far_today10);
TodayOpen = Sum(O,Bars_so_far_today10);
TWAP_10 = (TodayClose + TodayHigh + TodayLow + TodayOpen)/4 ;
IIf (BarIndex() >= StartBar, ATWAP_10 = TWAP_10 / Bars_so_far_today10,0);
ATWAP_10_Color = IIf(ATWAP_10 >= Ref(ATWAP_10,-1),colorYellow,colorBrown);
Plot(ATWAP_10,"",ATWAP_10_Color, styleline+styleThick|styleNoLabel,Null, Null, 0, 1, 2);

BUY_5_10 = Cross(ATWAP_5,ATWAP_10);
SELL_5_10 = Cross(ATWAP_10,ATWAP_5);
PlotShapes(shapeUpArrow*BUY_5_10, colorGreen, 0, L, -20 );
PlotShapes(shapeDownArrow*SELL_5_10, colorOrange, 0, H, -40 );

_SECTION_END();

That’s work Mr Tradinology
Thank you, Big Thank You

You’re most welcome, if you have any idea that can help make this indicator more useful pls share so everyone can learn something new,,,

thanks

It’s a filter code in (explone) in AmiBroker based in the indicator Ichimoku Kinko Hyo chart of the full range of items as shown in the table. filtering based on the chart and the Ichimoku signals are as follows;

strong buy signal; tenkansen cut prices or Kijun sen from the bottom up position above the clouds cut kumo, the direction from the bottom up. tenkan Kijun above the clouds from below kumo. Price cloud kumo break upward.
Weak buy signal; price cut tenkan sen sen or Kijun upward position kumo cloud bottom cutter, cut up Kijun sen sen Tankan bottom kumo cloud.
All the signals occurred in the context of cloud kumo average signals are buy and sell even.
Strong sell signal: price cut Tankan sen sen or Kijun from above down to the lower cutter cloud kumo
Weak sell signal; Tankan cut prices or Kijun sen sen from above down to the blades above the cloud kumo

big thanks! very transparent indicator. Helpful!!!

Please login here to leave a comment.

Main Menu

Indicators

Sponsors