NexusFi: Find Your Edge


Home Menu

 





Sierra Chart coding - how to call a function only once


Discussion in Sierra Chart

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




 
Search this Thread
  #1 (permalink)
 
Oysteryx's Avatar
 Oysteryx 
New York, NY
 
Experience: Master
Platform: Various
Trading: Everything that moves
Posts: 217 since Feb 2014
Thanks Given: 340
Thanks Received: 466

I need to run a s_SCNewOrder function only once, upon certain condition being met the first time only (for example price greater than X).

I have been looking at ways to achieve that in C++ (this thread for example c++ - How to make sure a function is only called once - Stack Overflow) but not sure yet how to implement this in ACSIL.

Would anyone here know?


Follow me on X Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Strike Pause Holds, Oil Erases Monday Spike -- May CPI W …
Traders Hideout
Pakistan Mediator in Tehran as Hormuz Normalization Coll …
Prediction Markets & Event Contracts
Warsh Rate Hike at 40%, Iran June 15 Expires Tonight at …
Prediction Markets & Event Contracts
NinjaTrader Parent Payward Acquires Bitnomial for $550M …
Platforms and Indicators
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #2 (permalink)
 
Oysteryx's Avatar
 Oysteryx 
New York, NY
 
Experience: Master
Platform: Various
Trading: Everything that moves
Posts: 217 since Feb 2014
Thanks Given: 340
Thanks Received: 466

SCENARIO = THERE IS A LONG POSITION WITH AN ATTACHED STOP BELOW

bool flag = true;

//Find PreExistingStop ID
s_SCTradeOrder PreExistingStop;
int StopResult = sc.GetNearestStopOrder(PreExistingStop);
int PreExistingStopOrderID = PreExistingStop.InternalOrderID;

//Get position data
s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);

//Run the following only on the most recent bar
if (sc.Index == sc.ArraySize - 1)
{

//this says execute if flag=true and the distance between the high and the PositionData.AveragePrice is >= 10
if (((max(sc.High[sc.Index],sc.High[sc.Index-1]) - PositionData.AveragePrice) >= 10))
&& flag)
{

int Result = sc.CancelOrder(PreExistingStop.InternalOrderID); // this cancels the PreExistingStop

if (Result > 0) // if PreExistingStop succesfully cancelled enter new sell stop at 1800 and make flag=false
{
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 1;
NewOrder.OrderType = SCT_ORDERTYPE_STOP;
NewOrder.TimeInForce = SCT_TIF_GTC;
NewOrder.Stop1Price = 1800;
int Result = sc.SellEntry(NewOrder);

flag = false;
}

}
}

Once the trigger is reached, if flag=true, that 1) cancels the preexisting stop, 2) creates a new stop at 1800, and 3) makes flag=false.

THIS WORKED.

Needed to tinker with the following to get it to work:
sc.AllowEntryWithWorkingOrders = true;
sc.AllowOnlyOneTradePerBar = false;
sc.AllowMultipleEntriesInSameDirection = true;


Follow me on X Started this thread Reply With Quote
Thanked by:




Last Updated on February 20, 2016


© 2026 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 - Downloads - Top
no new posts