NexusFi: Find Your Edge


Home Menu

 





Sierra Chart coding - how to call a function only once


Discussion in Sierra Chart

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




 
Search this Thread

Sierra Chart coding - how to call a function only once

  #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 Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
Cheap historycal L1 data for stocks
Stocks and ETFs
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #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 Twitter Started this thread Reply With Quote
Thanked by:




Last Updated on February 20, 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