NexusFi: Find Your Edge


Home Menu

 





shift boolean to previous bar


Discussion in NinjaTrader

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




 
Search this Thread

shift boolean to previous bar

  #1 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

Hello to the Forum,
I would like to ask for your assistance with the following question.

I want to synchronize different filters that use boolean variables.

For this I have to move a true condition to the previous bar.

Example: A condition becomes true at bar x,y,z.
How can I set the condition at the previous bar x-1,y-1,z-1 to true.

Thank you very much for your support and stay healthy!
user10

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
Increase in trading performance by 75%
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
11 thanks
HumbleTraders next chapter
11 thanks
  #2 (permalink)
MartinLmpidCom
Dresden, Germany
 
Posts: 3 since Apr 2020
Thanks Given: 1
Thanks Received: 0

Hey user10,

you can use

CurrentBar - BarsAgo = index of bar


In your case, this means

CurrentBar - 1 = previous bar


Best regards from near Dresden
Martin

Reply With Quote
  #3 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5


Hello Martin,

Thank you for the advice.
My problem is more complex.
In the history I calculate different filters which have to be synchronized.

By means of a list I get the respective beginning of a true condition.
This condition entry should now be moved one bar into the past.

All attempts to achieve this with currentbar have failed.
This makes sense, because the respective calculation only takes place at the current bar...

In my understanding I have to use a programming that calculates backwards at the last historical bar and then sets the condition to true at the previous bar.

I did not succeed with an array or a list.

Do you have an idea how I can solve the problem?

Thanks a lot
user10

PS: Grüße nach Sachsen

Reply With Quote
  #4 (permalink)
MartinLmpidCom
Dresden, Germany
 
Posts: 3 since Apr 2020
Thanks Given: 1
Thanks Received: 0

Hey User10,

do you have a concrete example for me?

We will find a solution for this!

Reply With Quote
  #5 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

Hello Martin,

The goal is to move the condition one bar to the left.
I can't do this with the approach BarsAgo or with a list that displays the previous bar.

What am I doing wrong?

Regards
user10




 
Code
                            


protected override void OnBarUpdate()
{
    if (
BarsInProgress != 0) return;
    if (
CurrentBars[0] < 1) return;

    
// Test BarsAgo
    
myCond CrossAbove (SMA1SMA2,1) ? true false;
    if (
myCondDraw.VerticalLine(this"myCond"CurrentBar0Brushes.RedDashStyleHelper.Solid3);
    
    if (
myCondmyCondPrevSeries[1] = true// does not work ==> same result as myCond
    
if (!myCondmyCondPrevSeries[1] = false
//    if (myCondPrevSeries[1]) Draw.VerticalLine(this, "myPrevCond"+ CurrentBar, 0, Brushes.Black, DashStyleHelper.Solid, 3);
    
    
    // Test List
    
if (myCond) {myList.Add(CurrentBar);}
    for (
int i=0myList.Counti++)
    {
        
previousEventCounter myList[i] - 1// returns PreviousBar 
        
if (Bars.IsLastBarOfSession) Print ("Event # "+i"  Occured on bar: "+myList[i] + " previousEventCounter " previousEventCounter);
    }            

    
myListCond =  (CurrentBar == previousEventCounter) ? true false// will never reach this value?
//    if (myListCond) Draw.VerticalLine(this, "myListCond"+ CurrentBar, 0, Brushes.Cyan, DashStyleHelper.Solid, 3);
    
    
Print (Time[0]
    + 
" Try BarsAgo "
    
"    myCond    " myCond
    
"    myCondPrevSeries[1]  "myCondPrevSeries[1
    
    + 
" Try List"
    
"    CurrentBar  "CurrentBar
    
"    previousEventCounter  "previousEventCounter);


Reply With Quote
  #6 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


user10 View Post
Hello to the Forum,
I would like to ask for your assistance with the following question.

I want to synchronize different filters that use boolean variables.

For this I have to move a true condition to the previous bar.

Example: A condition becomes true at bar x,y,z.
How can I set the condition at the previous bar x-1,y-1,z-1 to true.

Thank you very much for your support and stay healthy!
user10

Use a Series<bool> and set the value to the bars x-1, y-1 and z-1. This series can be handled in the same way as a Series<double>.

Reply With Quote
Thanked by:
  #7 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

Hello, Fat Tails,

thank you very much for your hint!
I have been trying to solve the problem for a few days now.

How do I assign a value to the previous bar?
Using a boolean series does not work; in my example I had formulated this.
What am I doing wrong?

According to my understanding I can't work with currentBar == previousEventCounter ==> this value will never be reached.

I am currently working on a solution with a for loop that counts backwards. I have no success with that either.

I am grateful for any support.



Thanks a lot and stay healthy!
user10

Reply With Quote




Last Updated on May 4, 2020


© 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