NexusFi: Find Your Edge


Home Menu

 





Plot only once help


Discussion in MultiCharts

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




 
Search this Thread

Plot only once help

  #1 (permalink)
 olobay 
Montreal
 
Experience: Intermediate
Platform: MultiCharts
Broker: DeepDiscountTrading.com
Trading: CL
Posts: 364 since Jul 2011

Hi,

I have this Show Me code that I would like to plot only once, only the first time the conditions are met. Or if the last plot was a "Buy" plot, then the next plot can only be a "Sell" plot. So it would alternate between one plot for a sell and the next plot for a buy and then the next plot would be a sell. But I think it would be easier if the code would just plot it once the first time the conditions are met. Any help is appreciated.

 
Code
input: offset(.05);

variables: Range(0);

Range=(Open + Close) /2;

if close of Data2 >= Range of Data1 then
	begin
	Plot1( Low - offset, "Buy") ;
	end
	Else Begin
	NoPlot(0);
	end;
	
if close of Data2 <= Range of Data1 then
	begin
	Plot1( High + offset, "Sell") ;
	end
	Else Begin
	NoPlot(0);
	end;

Attached Thumbnails
Click image for larger version

Name:	No plot.png
Views:	175
Size:	20.9 KB
ID:	222677  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #2 (permalink)
 
tradingest's Avatar
 tradingest 
Milan, Italy
 
Experience: Master
Platform: NT8
Trading: Futures, Forex
Posts: 111 since Dec 2014
Thanks Given: 9
Thanks Received: 11

you can use Once to plot one time

Reply With Quote
Thanked by:
  #3 (permalink)
 olobay 
Montreal
 
Experience: Intermediate
Platform: MultiCharts
Broker: DeepDiscountTrading.com
Trading: CL
Posts: 364 since Jul 2011


I tried the following but it only plotted the first time the condition happened on the chart. I don't think I was clear. I would like it to plot every time my condition is met, but only the first bar that it is met and not every single bar.

 
Code
input: offset(.05);

variables: Range(0);

Range=(Open + Close) /2;

once (close of Data2 >= Range of Data1)
	begin
	Plot1( Low - offset, "Buy") ;
	end;
	
once (close of Data2 <= Range of Data1)
	begin
	Plot1( High + offset, "Sell") ;
	end;
This is where I would like it to plot but only on the bars with arrows:


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

olobay,

you could use a boolean variable that you check together with your condition. If your conditions are met, you will set the boolean to true as well. Now you just have to reset the boolean to false again in order to allow for a new plot - when you do that depends on when you want to allow another plot again (for example after X bars, when the conditions are not fulfilled anymore or with the opposite plot etc.).

 
Code
Variables:
haveBuyPlot ( false );

if close of Data2 >= Range of Data1 and haveBuyPlot = false then
	begin
        haveBuyPlot = true ;
	Plot1( Low - offset, "Buy") ;
	end;
Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
 olobay 
Montreal
 
Experience: Intermediate
Platform: MultiCharts
Broker: DeepDiscountTrading.com
Trading: CL
Posts: 364 since Jul 2011


ABCTG View Post
olobay,

you could use a boolean variable that you check together with your condition. If your conditions are met, you will set the boolean to true as well. Now you just have to reset the boolean to false again in order to allow for a new plot - when you do that depends on when you want to allow another plot again (for example after X bars, when the conditions are not fulfilled anymore or with the opposite plot etc.).

Regards,

ABCTG

Thanks for the help. I understand in English what I need to do, but I have no idea how I should state it or where to place it in the code. I want to have only one bar with a dot and alternating dots, one for a sell and the next for a buy and the next for a sell again. This only plots once on the first occurrence on the chart.

 
Code
input: offset(.05);

variables: Range(0), haveBuyPlot(false), haveSellPlot(false);

Range=(Open + Close) /2;

if close of Data2 >= Range of Data1 and haveBuyPlot = false then
	begin
	haveBuyPlot = true ;
	Plot1( Low - offset, "Buy") ;
	end;
	
if close of Data2 <= Range of Data1 and haveSellPlot = false then
	begin
	haveSellPlot = true ;
	Plot1( High + offset, "Sell") ;
	end;

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

olobay,

your code correctly does the first part of "If your conditions are met, you will set the boolean to true", you just need to do the second part "reset the boolean to false again [...] with the opposite plot". This is missing in the code and that's why you just get one plot for the very first occurrence at the moment.

In other words, when you set haveBuyPlot to true, you need to set haveSellPlot to false and vice versa. This will allow a new plot the next time your conditions are fulfilled.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on December 6, 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