NexusFi: Find Your Edge


Home Menu

 





How to Place Order just once in a candle


Discussion in Platforms and Indicators

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




 
Search this Thread
  #1 (permalink)
raghavan
Bangalore + India
 
Posts: 13 since Jan 2015
Thanks Given: 3
Thanks Received: 2

I have a code

 
Code
_SECTION_BEGIN("Test");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Buy = Cross(MA(C, 5), MA(C, 20));
Short = Cross(MA(C, 20), MA(C, 5)) OR C<O;

Sell = short;
cover = buy;
PlotShapes(shapeUpArrow*Buy, colorBlue, 0, low);
PlotShapes(shapeDownArrow*Short, colorPink, 0, high);


dist = -12;
fnt = "Arial";
fntsize = 8;
txtdist = 25 - dist;
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
        if( Buy[i] ) 
            PlotTextSetFont( StrFormat( "B@\n%g", BuyPrice[ i ] ), fnt, fntsize, i, L[ i ], colorBlue, colorDefault, -txtdist + fntsize );
       	if( Short[i] )
            PlotTextSetFont( StrFormat( "Sh@\n%g", ShortPrice[ i ] ), fnt, fntsize, i, H[ i ], colorYellow, colorDefault, txtdist);
}
_SECTION_END();
I am using this in 1 minute candle. What I notice is that, depends on market movement, within same candle, it initially places buy signal and disappears depends on market movement and, after a while, it places short signal and again that disappears too.

May I know how to place these orders only once in a candle and it should not disappear once its placed.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
tick data interval discrepancy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Help re translation of ninjascript to EL
NinjaTrader
Pivot Indicator based on Level2 data
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
ApexTraderFunding.com experience and review
74 thanks
HumbleTraders next chapter
51 thanks
Winning attitudes create winning traders
39 thanks
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Topstep experience and review
33 thanks
  #2 (permalink)
 prouser 
Zurich/Switzerland
 
Posts: 79 since Oct 2014

Do you trade for the first time?

Of course signals disappear in real-time on last bar if calculation includes last bar since MA calculation depends on close price and in your case current price can move above or below of MA while bar is not finished yet. So signals may appear or disappear on very last bar.

If you don't want to calculate on current bar but on previous one(s) then use Ref() to check signal for true/false on previous bar(s).

 
Code
...
Buy = Cross(MA(C, 5), MA(C, 20)); 
Short = Cross(MA(C, 20), MA(C, 5)) OR C<O;

Buy = Ref( Buy, -1 );
Short = Ref( Short, -1 );
...

Or if in realtime you only want to do execute calculation on current bar when it is finished then i.e. use status( "lastbarend" )


Here is a sample function by Janeczko
 
Code
function NewBarJustArrived()
{ // sample function by T. Janeczko
    vname = "lbe" + GetChartID();
    prev = Nz( StaticVarGet( vname ) );
    curr = Status( "lastbarend" );
    StaticVarSet( vname, curr );
    return curr != prev;
}

Example?

Perhaps like this one

 
Code
function NewBarJustArrived()
{ // sample function by T. Janeczko
    vname = "lbe" + GetChartID();
    prev = Nz( StaticVarGet( vname ) );
    curr = Status( "lastbarend" );
    StaticVarSet( vname, curr );
    return curr != prev;
}

shortcond = Cross( MA( C, 20 ), MA( C, 5 ) ) OR C < O;
buycond = Cross( MA( C, 5 ), MA( C, 20 ) );

if( NewBarJustArrived() ) {	
	StaticVarSet( "Buycond", buycond, persist = false );
	StaticVarSet( "Shortcond", shortcond, persist );
} 

Buy = StaticVarGet( "Buycond" );
Short = StaticVarGet( "Shortcond" );

Sell = Short;
Cover = Buy;

//Buy = ExRem( Buy, Sell );
//Sell = ExRem( Sell, Buy );
//Short = ExRem( Short, Cover );
//Cover = ExRem( Cover, Short );

SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorBlue, 0, low );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorPink, 0, high );

dist = -12;
fnt = "Arial";
fntsize = 8;
txtdist = 25 - dist;
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
        if( Buy[i] ) 
            PlotTextSetFont( StrFormat( "B@\n%g", BuyPrice[ i ] ), fnt, fntsize, i, L[ i ], colorBlue, colorDefault, -txtdist + fntsize );
       	if( Short[i] )
            PlotTextSetFont( StrFormat( "Sh@\n%g", ShortPrice[ i ] ), fnt, fntsize, i, H[ i ], colorYellow, colorDefault, txtdist);
}
Or whatever ...

Reply With Quote
  #3 (permalink)
bob303
paris France
 
Posts: 5 since Mar 2014
Thanks Given: 1
Thanks Received: 1


_SECTION_BEGIN("Test");

// Try this I use Barindex for wait the end of the last bar for trigger the signal

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

Buy = Cross(MA(C, 5), MA(C, 20)) & BarIndex() < lastvalue( barindex() );
Short = ( Cross(MA(C, 20), MA(C, 5)) OR C<O ) & BarIndex() < lastvalue( barindex() )

Sell = short;
cover = buy;
PlotShapes(shapeUpArrow*Buy, colorBlue, 0, low);
PlotShapes(shapeDownArrow*Short, colorPink, 0, high);


dist = -12;
fnt = "Arial";
fntsize = 8;
txtdist = 25 - dist;
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
if( Buy[i] )
PlotTextSetFont( StrFormat( "B@\n%g", BuyPrice[ i ] ), fnt, fntsize, i, L[ i ], colorBlue, colorDefault, -txtdist + fntsize );
if( Short[i] )
PlotTextSetFont( StrFormat( "Sh@\n%g", ShortPrice[ i ] ), fnt, fntsize, i, H[ i ], colorYellow, colorDefault, txtdist);
}
_SECTION_END();

Reply With Quote




Last Updated on July 5, 2015


© 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