PlotText result is overlapped - AmiBroker | futures io social day trading
futures io futures trading


PlotText result is overlapped
Updated: Views / Replies:616 / 2
Created: by raghavan Attachments:1

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

PlotText result is overlapped

  #1 (permalink)
Trading Apprentice
Bangalore + India
 
Futures Experience: Beginner
Platform: NinjaTrader, MetaTrader
Favorite Futures: Futures
 
Posts: 13 since Jan 2015
Thanks: 3 given, 2 received

PlotText result is overlapped

I use below code

priceatbuy=0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 && Buy[ i ] )
priceatbuy = BuyPrice[ i ];

PlotText("P" + priceatbuy, SelectedValue(BarIndex()), L[SelectedValue(BarIndex())] - ist[SelectedValue(BarIndex())], colorWhite);
if( priceatbuy > 0 && SellPrice[ i ] < (priceatbuy - (0.027 * priceatbuy/100)) )
{
Sell[ i ] = 1;
SellPrice[ i ] = (priceatbuy - (0.027 * priceatbuy/100)) ;
plotShapes(shapeDownArrow*sell, colorpink );
priceatbuy = 0;
}
else
Sell[ i ] = 0;
}

With above plotText, when i print the variable "priceatBuy", i see the text is overlapped and I am not able to see the value correctly. Is it because that SellPrice[i] and BuyPrice[i] returning some other value that Plottext doesnt understand? If I print Sell[i] or Buy[i], it prints correctly. May I know how to get this value correctly.

PFA image

Attached Thumbnails
PlotText result is overlapped-overlapped.png  

Last edited by raghavan; June 16th, 2015 at 11:51 AM. Reason: Image corrected
Reply With Quote
 
  #2 (permalink)
Membership Temporarily Revoked
Zurich/Switzerland
 
Futures Experience: Advanced
Platform: -
Favorite Futures: -
 
Posts: 79 since Oct 2014
Thanks: 0 given, 33 received

Your code is pretty much incorrect because of lacking basic skills in programming and mathematics.

Your usage of plot is not properly done. Plot shapes moves outside of loop.
And Plottext needs iteration of visible chart area only to get some signal text output on chart instead of iteration of entire barcount. Latter one is rather overkill. And there should be an additional condition inside such loop where there is text output at signal occurrence only. Another major mistake in your code is that you use array functions inside of barcount loop. That is similar horror as fingernails on a blackboard. In short it's a no go.

So better consult the AB documention first -> i.e. "Coding mistakes"
Also search "Understanding how AFL works".

Here is corrected SL loop

 
Code
percent = 2.7; // percent SL
delay = 1; // buy entry bar delay

Buycond = Cross( MACD(), Signal() ); // buy when macd crosses above of signal line
Buy = Ref( Buycond, -delay );
BuyPrice = Open;

Sell = 0;
priceatbuy = 0;
for( i = delay; i < BarCount; i++ ) {
    // setting SL line
    if( priceatbuy == 0 && Buy[ i ] )
        priceatbuy = BuyPrice[ i ] * ( 1 - percent / 100 );  
    else {
        Buy[ i ] = 0;
    }
    // if SL is reached exit and reset
    Sellsignal = L[ i ] < priceatbuy;
    if( priceatbuy > 0 && Sellsignal ) {
        Sell[ i ] = 1;
        SellPrice[ i ] = Min( O[ i ], priceatbuy );       
        priceatbuy = 0;
    } else
        Sell[ i ] = 0;
}
Keep in mind that upper loop contains SL exit only but no profit exit.
So you have to add some profit exit too otherwise you always exit at loss.

As seen here

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Last edited by prouser; June 18th, 2015 at 07:07 AM.
Reply With Quote
The following user says Thank You to prouser for this post:
 
  #3 (permalink)
Membership Temporarily Revoked
Zurich/Switzerland
 
Futures Experience: Advanced
Platform: -
Favorite Futures: -
 
Posts: 79 since Oct 2014
Thanks: 0 given, 33 received


Here is code including plot of shapes, text and SL line.
Again, the loop contains SL exit only. So you need to add some profit exit condition too.


 
Code
// fix of SL plot & text
// by prouser
// source https://futures.io/amibroker/36055-plottext-result-overlapped.html

percent = 2.7; // percent SL
delay = 1; // buy entry bar delay

Buycond = Cross( MACD(), Signal() ); // buy when macd crosses above of signal line
Buy = Ref( Buycond, -delay );
BuyPrice = Open;

Sell = 0;
SLlong = Null;
SLLineLong = Null; // array
for( i = delay; i < BarCount; i++ ) {
    // setting long SL line
    if( IsNull( SLlong ) && Buy[ i ] )
        SLlong = BuyPrice[ i ] * ( 1 - percent / 100 );  
    else { 
        Buy[ i ] = 0;
    }
    // no shape buy signal if SL not hit
    if( NOT IsNull( SLlong ) && BuyCond[ i ] )
        Buycond[ i ] = 0; 
    // if SL is reached exit and reset
    Sellsignal = L[ i ] < SLlong;
    if( NOT IsNull( SLlong ) && Sellsignal ) {
        Sell[ i ] = 1;
        SellPrice[ i ] = Min( O[ i ], SLlong );       
        SLlong = Null;
    } else
        Sell[ i ] = 0;
    //
    // for plotting SL line array is required
    SLLineLong[i] = SLlong;
}

// Chart pane section
if( Status( "action" ) == actionIndicator ) {
    SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
    // Plot price
    Plot( C, "", colorDefault, GetPriceStyle() );
    // Plot SL line
    Plot( SLLineLong, "\nSL long", colorRed, styleLine | styleNoRescale );
    //
    // Plot Shapes
    dist = -12;
    PlotShapes( shapeUpArrow * Buycond, colorGreen, 0, L, dist );
    PlotShapes( shapeSmallCircle * Buy, colorGreen, 0, BuyPrice, 0 );
    PlotShapes( shapeDownArrow * Sell, colorPink, 0, H, dist );
    PlotShapes( shapeSmallCircle * Sell, colorPink, 0, SellPrice, 0 );
    //
    // Plot signal text
    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] )  // plot text at signal occurences only
            PlotTextSetFont( StrFormat( "BP@\n%g", BuyPrice[ i ] ), fnt, fntsize, i, L[ i ], colorGreen, colorDefault, -txtdist + fntsize );
        if( Sell[i] )
            PlotTextSetFont( StrFormat( "SP@\n%g", SellPrice[ i ] ), fnt, fntsize, i, H[ i ], colorPink, colorDefault, txtdist );
    }
    //
    _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}",
                           O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
    //
    SetBarsRequired( 10000, 10000 );
}
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


EDIT: some code fix added


Last edited by prouser; June 18th, 2015 at 07:07 AM.
Reply With Quote
The following user says Thank You to prouser for this post:

Reply



futures io > > > > PlotText result is overlapped

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Poll result: Favorite chart size Big Mike Traders Hideout 6 January 14th, 2017 03:06 PM
Syria and the stock market result Big Mike Off-Topic 30 September 12th, 2013 01:54 AM
Poll result: Risk vs. Reward Big Mike Traders Hideout 0 June 11th, 2009 11:39 PM


All times are GMT -4. The time now is 07:45 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-15 in 0.08 seconds with 20 queries on phoenix via your IP 54.163.61.66