NexusFi: Find Your Edge


Home Menu

 





Rewriting DATE NEXT BAR <> DATE - Simple Help


Discussion in Traders Hideout

Updated
    1. trending_up 3,321 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Rewriting DATE NEXT BAR <> DATE - Simple Help

  #1 (permalink)
 fiverr 
Calgary
 
Experience: None
Platform: TradeStation, MT4
Trading: ES, Stocks
Posts: 73 since Aug 2015
Thanks Given: 4
Thanks Received: 11

Hi there,

I have the following simple problem

 
Code
DATE NEXT BAR <> DATE
How can I rewrite the code so that it does not use NEXT BAR?

I tried DATE <> DATE[1] but it does not behave the same.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Quantum physics & Trading dynamics
The Elite Circle
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


fiverr,

someone might be able to help you, if you could elaborate what you are trying to accomplish.

A correct answer to your question (although obviously not what you want) would be:

 
Code
Date <> Date
This would be the code re-written, without using next bar - taking your question literally.

As another person usually doesn't know your intend, it's extremely helpful to provide as much context and explanations as possible - what does the code do now, what do you want it to do instead etc.. If you want people being able to help you, it can also make sense to state the platform you want the help for and post into the correct section of the forum.
Just to make it clear, I am trying to help and the above is meant as that and no criticism.

When you apply the following code (in a signal) to an intraday chart, you will see why the two are different:
 
Code
If Date <> Date[1] then
	Print( BarDateTime.Format( "%m-%d-%y  %H:%M" ), "; Date <> Date[1]", "; BarNumber: ", CurrentBar ) ;       
	
if Date next bar <> Date then
	Print( BarDateTime.Format( "%m-%d-%y  %H:%M" ), "; Date next bar <> Date", "; BarNumber: ", CurrentBar ) ;
Date <> Date[1] will become true on the first bar of the new day, while Date next bar <> Date is true on the last bar of the current day already (as at that time the date of the NEXT BAR is already the next date).

One approach might be to change the codes that are affected by that, so they give you the same results when using Date <> Date[1].

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 fiverr 
Calgary
 
Experience: None
Platform: TradeStation, MT4
Trading: ES, Stocks
Posts: 73 since Aug 2015
Thanks Given: 4
Thanks Received: 11


ABCTG View Post


Date <> Date[1] will become true on the first bar of the new day, while Date next bar <> Date is true on the last bar of the current day already (as at that time the date of the NEXT BAR is already the next date).

One approach might be to change the codes that are affected by that, so they give you the same results when using Date <> Date[1].

Regards,

ABCTG

ABCTG,

Thanks for the tips. I am currently using Multichart and I had to change your code.

 
Code
print(datetimetostring_ms(datetime_bar_update));


If Date <> Date[1] then
	Print( datetimetostring_ms(datetime_bar_update), "; Date <> Date[1]", "; BarNumber: ", CurrentBar ) ;       
	
//if Date next bar <> Date then
if Date next bar <> Date then
	Print( datetimetostring_ms(datetime_bar_update), "; Date next bar <> Date", "; BarNumber: ", CurrentBar ) ;
Below are my output:

2015-08-25 15:00:00.000
2015-08-25 15:15:00.000
2015-08-25 15:15:00.000; Date next bar <> Date; BarNumber: 51268.00
2015-08-26 09:00:00.000
2015-08-26 09:00:00.000; Date <> Date[1]; BarNumber: 51269.00
2015-08-26 09:30:00.000

Below is my original strategy that is running on 30M chart.

 
Code
if DATE NEXT BAR <> DATE OR ATR_check = FALSE then
   Begin
      if DATE NEXT BAR <> DATE then
      Begin
         average_20C = Average (CLOSE, 20);
      End ;
      prev_ATR_check = ATR_check ;
   End ;
I would like to modify the above code to do 2 things: 1) run on the 1M chart but still referencing the 30M logic 2) to avoid using "DATE NEXT BAR".

Your help is greatly appreciated.

Started this thread Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

fiverr,

what exactly do you mean with "still referencing the 30M logic" exactly? What should it apply to and what not?

If you are running your strategy without intrabar order generation on a 30 min chart, you have access to the values at the end of that 30 min bar. This is something you can't overcome, unless you are willing to act on values that might be different than they would be at the end of the bar. Take the average for example: Over the course of the bar it will have different values. Your current signal acts on the end of bar values for that average, but if you are trying to act on the average's values already mid bar for example, the results will likely be different than in your original strategy (simply because you are looking at different data).

You also might want to do @BigMike a favor and not post the same questions multiple times across different threads.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

This is what I meant under #3, it's very hard to understand what you are trying to accomplish with the information you provide:

MultiCharts: Trading Software for Automated Trading and [AUTOLINK]Backtesting[/AUTOLINK] ? View topic - Rewriting DATE NEXT BAR <> DATE

Follow me on Twitter Reply With Quote
  #7 (permalink)
 fiverr 
Calgary
 
Experience: None
Platform: TradeStation, MT4
Trading: ES, Stocks
Posts: 73 since Aug 2015
Thanks Given: 4
Thanks Received: 11


ABCTG View Post
fiverr,

what exactly do you mean with "still referencing the 30M logic" exactly? What should it apply to and what not?


Regards,

ABCTG


ABCTG,

I did not want to scare readers by posting a large amount of code so I tried to keep it as simple as possible. It backed fire on me. Anyhow, you have helped me out a lot and I think that I got a temporary solution. Before I was attaching the code to the 30M chart, using the code below I am attaching the code to 1M chart. This is what I mean by using 1M chart but referencing 30M chart.

Data1 - 1M chart
Data2 - 30M chart

 
Code
Variables: average_20C(0, data(2));

if Time >= 1500 OR ATR_check = FALSE then
   Begin
      if Time >= 1500 then
      Begin
         average_20C = Average (CLOSE, 20)of data(2);
      End ;
      prev_ATR_check = ATR_check ;
   End ;

Started this thread Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

fiverr,

you are welcome. You might want to specify that the average should use the Data 2 Close, although for the closing price this might not even matter (for High and Low for example it will, though, as these will be different).

 
Code
average_20C = Average (CLOSE Data2, 20)of data(2);
Regards,

ABCTG

Follow me on Twitter Reply With Quote




Last Updated on May 11, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts