How to know last bar on the chart
Forums › ProRealTime English forum › ProBuilder support › How to know last bar on the chart
- This topic has 3 replies, 2 voices, and was last updated 6 years ago by Tobees.
-
-
12/28/2017 at 6:15 PM #56751
Hi,
I’m starting coding with PRC and I have some problems with the following:
To know if the last bar on the chart (most right one) I use the following code: ===>> If date=Today then
This works perfect for daily charts but dosn’t work for weekly and/or monthly charts.
So how can I determine when I reach the last bar on the chart (most right one, current week or month)
Thnx
12/28/2017 at 7:57 PM #56760You can get a code snippet in this thread: How to know EOF? the last barindex?
It returns true if the current bar is the last known one.
12/28/2017 at 9:17 PM #56764Nicolas,
LastBarOnChart=currenttime=opentime and date=today
==> doesn’t work like I need it.
I enclose the programming, it is the Swing Counter Indicator. I think you wrote it, I modified it a litle.µ
This code works fine with daily charts, it doesn’t work with charts on weekly or monthly basis.
How can I make it work for whatever period I use (fi week – month)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697//Swing Counter | indicator//Version 1.1 | 28.12.2017//Author: Tobees//Based on: PRC_swing teller live count2 | indicator//07.04.2017//Nicolas @ www.prorealcode.com//Description Indicator://This indicator is based on the "PRC_swing teller live count2 | indicator" written by Nicolas. I modified it a little => when the swing doesn’t succeed in //reaching its full up or downswing (+9 or -9) it will be discarded and not drawn on the chart.//This indicator is a part of a swing strategy described as follows by users in the forum://Swing +1 starts when the candle closes higher then the 4 candles before.//Swing -1 starts when the candle closes lower then 4 candles before.//When a Fully swing has appeared (Swing 1 -> 9) it stops counting because the 10th candle is called the resting candle.//If the 11th candle also closes higher then the 4 candles before the swing starts again at swing 1 (in blue colour and red for -1). Also if a swing doesn’t //succeed in reaching number 9, the swing has failed and will NOT be drawn on the chart.//The main purpose of this indicator is to signal a reversal. When a full swing +9 or -9 has appeared the chances of an upcoming bottom or a top increases a lot. //A fully upswing +9 combined with a red 10th candle suggest to exit your long position. Its the same for a downswing -9 combined with a 10th green candle means //exit your short position.//Variables://CountDistance: The 1 to 9 numbers distance form high or low of candlestick can be modified with the "CountDistance" setting.//Swingpointer: Points to 4 bars ago//Upcount: UpSwing Counter//DownCount: DownSwing Counter//BarPointer: Identifies the bar on wich above (or below) the SwingNr will be drawn//SwingNr: Contains the Swing number in the Up or DownSwing//Last9Bar: Used to identify the 10th bar after a succesfull Swing - Resting BarOnce SwingPointer=4//LastBarOnChart=currenttime=opentime and date=todayLastBarOnChart=date=today//continue swing Upif UpCount>0 and Close>Close[SwingPointer] thenDownCount=0UpCount=UpCount+1//Draw Full Upswing (9 downto 1) or draw Ongoing Upswing if Last bar on chartif UpCount=9 or LastBarOnchart thenBarPointer=0for SwingNr=Upcount downto 1 dodrawtext("#SwingNr#",barindex-BarPointer,high[BarPointer]+CountDistance*pointsize,Dialog,Bold,16) coloured(0,0,250)BarPointer=BarPointer+1nextlast9bar=barindex//Reset UpSwing CounterUpCount=0endif//Failed UpSwingelsif UpCount>0 and Close<Close[SwingPointer] then//Reset UpSwing CounterUpCount=0endif//Continue DownSwingif DownCount>0 and Close<Close[SwingPointer] thenUpCount=0DownCount=DownCount+1//Draw Full Downswing (9 downto 1) or draw Ongoing DownSwing if Last bar on chartif DownCount=9 or LastBarOnChart thenBarPointer=0for SwingNr=DownCount downto 1 dodrawtext("#SwingNr#",barindex-BarPointer,low[BarPointer]-CountDistance*pointsize,Dialog,Bold,16) coloured(255,0,0)BarPointer=BarPointer+1nextlast9bar=barindex//Reset DownSwing CounterDownCount=0endif//Failed DownSwingelsif DownCount>0 and Close>Close[SwingPointer] then//Reset DownSwing CounterDownCount=0endif//Begin Upswingif UpCount=0 and barindex-last9bar>1 thenif close>close[SwingPointer] thenUpCount=1DownCount=0if LastBarOnChart then//Draw Start of UpSwing (only Today's bar)drawtext("1",barindex,high+CountDistance*pointsize,Dialog,Bold,16) coloured(0,0,250)endifendifendif//Begin Downswingif DownCount=0 and barindex-last9bar>1 thenif close<close[SwingPointer] thenDownCount=1UpCount=0if LastBarOnChart then//Draw Start of DownSwing (only Today's bar)drawtext("1",barindex,low-CountDistance*pointsize,Dialog,Bold,16) coloured(255,0,0)endifendifendifreturn12/29/2017 at 3:05 PM #56813Hi,
With try and error I found out the following:
I replaced ==> LastBarOnChart=date=today
with ==> Daylastbar=date=today //true if last bar on daychart is today – most right one on the chart
Weeklastbar=date-dayofweek+1=today //true if last bar on weekchart is this week – most right one on the chart
Monthlastbar=date-day+1=today //true if last bar on monthchart is this month- most right one on the chartAnd used these variables in the “if” conditions. => Are these calculations, to check if the most right bar in the day, week or month chart is the last one available (EOF) and therefore Today, correct??
So the code becomes as follows:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273Once SwingPointer=4Daylastbar=date=todayWeeklastbar=date-dayofweek+1=todayMonthlastbar=date-day+1=today//continue swing Upif UpCount>0 and Close>Close[SwingPointer] thenDownCount=0UpCount=UpCount+1//Draw Full Upswing (9 downto 1) or draw Ongoing Upswing if Last bar on chartif UpCount=9 or Daylastbar or Weeklastbar or Monthlastbar thenBarPointer=0for SwingNr=Upcount downto 1 dodrawtext("#SwingNr#",barindex-BarPointer,high[BarPointer]+CountDistance*pointsize,Dialog,Bold,16) coloured(0,0,250)BarPointer=BarPointer+1nextlast9bar=barindex//Reset UpSwing CounterUpCount=0endif//Failed UpSwingelsif UpCount>0 and Close<Close[SwingPointer] then//Reset UpSwing CounterUpCount=0endif//Continue DownSwingif DownCount>0 and Close<Close[SwingPointer] thenUpCount=0DownCount=DownCount+1//Draw Full Downswing (9 downto 1) or draw Ongoing DownSwing if Last bar on chartif DownCount=9 or Daylastbar or Weeklastbar or Monthlastbar thenBarPointer=0for SwingNr=DownCount downto 1 dodrawtext("#SwingNr#",barindex-BarPointer,low[BarPointer]-CountDistance*pointsize,Dialog,Bold,16) coloured(255,0,0)BarPointer=BarPointer+1nextlast9bar=barindex//Reset DownSwing CounterDownCount=0endif//Failed DownSwingelsif DownCount>0 and Close>Close[SwingPointer] then//Reset DownSwing CounterDownCount=0endif//Begin Upswingif UpCount=0 and barindex-last9bar>1 thenif close>close[SwingPointer] thenUpCount=1DownCount=0if Daylastbar or Weeklastbar or Monthlastbar then//Draw Start of UpSwing (only Today's bar)drawtext("1",barindex,high+CountDistance*pointsize,Dialog,Bold,16) coloured(0,0,250)endifendifendif//Begin Downswingif DownCount=0 and barindex-last9bar>1 thenif close<close[SwingPointer] thenDownCount=1UpCount=0if Daylastbar or Weeklastbar or Monthlastbar then//Draw Start of DownSwing (only Today's bar)drawtext("1",barindex,low-CountDistance*pointsize,Dialog,Bold,16) coloured(255,0,0)endifendifendifreturn -
AuthorPosts
Find exclusive trading pro-tools on