NexusFi: Find Your Edge


Home Menu

 





Questions and discussion for Sierra Chart ACSIL for Beginners


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one Trembling Hand with 43 posts (35 thanks)
    2. looks_two mosalem2003 with 40 posts (0 thanks)
    3. looks_3 1m1k3 with 20 posts (0 thanks)
    4. looks_4 bradhouser with 6 posts (9 thanks)
      Best Posters
    1. looks_one bobwest with 3.5 thanks per post
    2. looks_two bradhouser with 1.5 thanks per post
    3. looks_3 brach with 1 thanks per post
    4. looks_4 Trembling Hand with 0.8 thanks per post
    1. trending_up 28,077 views
    2. thumb_up 53 thanks given
    3. group 30 followers
    1. forum 119 posts
    2. attach_file 25 attachments




 
Search this Thread

Questions and discussion for Sierra Chart ACSIL for Beginners

  #41 (permalink)
mosalem2003
Toronto
 
Posts: 103 since Apr 2019
Thanks Given: 106
Thanks Received: 23

Thanks a lot Bob... I am using here a very simple concept for import a study subgraph. I did all the iterations suggested but for some reason the array is not imported correctly for only the subgraphs of the Dochian channel. My code logic is not the issue as the copy and paste solved it... This is my perception. You do have the whole code, and I tried the suggestion ... Do you have another idea ? I am not using here a long code or spaghetti. Its few lines to import a study subgraphs and place them into corresponding array.
The support team was stating that it's due to precedence whenever the question around this topic... I did remove the all suspected code by Trembling. Any idea what is the issue...?

Sent using the NexusFi mobile app

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Quantum physics & Trading dynamics
The Elite Circle
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
 
  #42 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360


mosalem2003 View Post
Thanks a lot Bob... I am using here a very simple concept for import a study subgraph. I did all the iterations suggested but for some reason the array is not imported correctly for only the subgraphs of the Dochian channel. My code logic is not the issue as the copy and paste solved it... This is my perception. You do have the whole code, and I tried the suggestion ... Do you have another idea ? I am not using here a long code or spaghetti. Its few lines to import a study subgraphs and place them into corresponding array.
The support team was stating that it's due to precedence whenever the question around this topic... I did remove the all suspected code by Trembling. Any idea what is the issue...?

Sent using the NexusFi mobile app

Mate!

You code isn't correct you have functions in functions.

And with a few get and stop/return blocks.

That's why it's not working. (even if it is pointing to the right index of the arrays which I'm still not sure it is)

It's poor coding.

To fix it you have too many moving parts within moving parts to find out what's wrong..

What you are trying to do is exactly what is not recommended with any programming language.

Follow me on Twitter Started this thread Reply With Quote
Thanked by:
  #43 (permalink)
mosalem2003
Toronto
 
Posts: 103 since Apr 2019
Thanks Given: 106
Thanks Received: 23


Thanks for the suggestion and feedback. I will try to optimize again once back from holidays and keep you posted with the progress.

Sent using the NexusFi mobile app

Reply With Quote
  #44 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360

Ok here is your trading system separated into two different studies. First one, Accumulation Trading Algo, takes the refernences to the DonchianChannel and Demand Index studies and plots the logic so you can see what is happening.

 
Code
SCSFExport scsf_AccumulationTEST(SCStudyInterfaceRef sc)
{

    SCSubgraphRef DC_High = sc.Subgraph[0];
    SCSubgraphRef DC_Low = sc.Subgraph[1];
    SCSubgraphRef DemandIndex = sc.Subgraph[2];

    SCSubgraphRef L2_Buyer = sc.Subgraph[3];
    SCSubgraphRef L2_Seller = sc.Subgraph[4];
    SCSubgraphRef DI_Buyer = sc.Subgraph[5];
    SCSubgraphRef DI_Seller = sc.Subgraph[6];


	//Inputs 
	///Imported studies subgraph(s) input arrays
	SCInputRef Input_Subgraph_DC_High = sc.Input[0];
	SCInputRef Input_Subgraph_DC_Low = sc.Input[1];
	SCInputRef Input_Subgraph_DemandIndex = sc.Input[2];
	

	//Subgraphs 


	// Set configuration variables

	if (sc.SetDefaults)
	{
		//Generic system defaults
		sc.GraphName = "Accumulation Trading Algo";
		sc.StudyDescription = "Accumulation Trading Study based on DonchianChannel and Demand Index";
		sc.GraphRegion = 0;
		sc.AutoLoop = 1;
		sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL;

		//Inputs' Arrays defaults

		//*SET/IMPORT* studies' subgraph(s)from the current chart: defaults to study 0, subgraph 0: change from the study settings to select the studies/subgraphs
		Input_Subgraph_DC_High.Name = "DC: High";
		Input_Subgraph_DC_High.SetStudySubgraphValues(1, 0);

		Input_Subgraph_DC_Low.Name = "DC: Low";
		Input_Subgraph_DC_Low.SetStudySubgraphValues(1, 1);

		Input_Subgraph_DemandIndex.Name = "DemandIndex";
		Input_Subgraph_DemandIndex.SetStudySubgraphValues(2, 0);


		//Subgraphs' arrays defaults 

        L2_Buyer.Name = "L2_Buyer";
        L2_Buyer.DrawStyle = DRAWSTYLE_IGNORE;
        L2_Buyer.PrimaryColor = RGB(0, 0, 200);

        L2_Seller.Name = "L2_Seller";
        L2_Seller.DrawStyle = DRAWSTYLE_IGNORE;
        L2_Seller.PrimaryColor = RGB(0, 0, 200);

        DI_Buyer.Name = "DI_Buyer";
        DI_Buyer.DrawStyle = DRAWSTYLE_IGNORE;
        DI_Buyer.PrimaryColor = RGB(0, 0, 200);

        DI_Seller.Name = "DI_Seller";
        DI_Seller.DrawStyle = DRAWSTYLE_IGNORE;
        DI_Seller.PrimaryColor = RGB(0, 0, 200);


		return;
	}

	//Setup for data processing 

	// **Get/IMPORT the array of the set studies(s) and corresponding subgraphs**

	//SCFloatArray DC_High;
	sc.GetStudyArrayUsingID(Input_Subgraph_DC_High.GetStudyID(), Input_Subgraph_DC_High.GetSubgraphIndex(), DC_High);


	//SCFloatArray DC_Low;
	sc.GetStudyArrayUsingID(Input_Subgraph_DC_Low.GetStudyID(), Input_Subgraph_DC_Low.GetSubgraphIndex(), DC_Low);

	//SCFloatArray DemandIndex;
	sc.GetStudyArrayUsingID(Input_Subgraph_DemandIndex.GetStudyID(), Input_Subgraph_DemandIndex.GetSubgraphIndex(), DemandIndex);



	// declare string to print log messages
	SCString SignalString;
	SCString LogString;


	// Process once per bar
	int& LastBarIndexProcessed = sc.GetPersistentInt(1);
	if (sc.Index == 0)
		LastBarIndexProcessed = -1;
	if (sc.Index == LastBarIndexProcessed)
		return;
	LastBarIndexProcessed = sc.Index;


	// Create an s_SCNewOrder object. 

	if (sc.Close[sc.Index - 1] > DC_Low[sc.Index - 1] && sc.Close[sc.Index - 2] <= DC_Low[sc.Index - 2])
	{
		L2_Buyer[sc.Index - 1] = sc.Close[sc.Index - 1];
		DI_Buyer[sc.Index - 1] = DemandIndex[sc.Index - 1];
        //LogString.Format("check 1 . sc.Close[sc.Index - 1]: %.2f, DemandIndex[sc.Index - 1]: %.2f", sc.Close[sc.Index - 1], DemandIndex[sc.Index - 1]);
		//sc.AddMessageToLog("check 1 ", 0);

	}
	else
	{
		L2_Buyer[sc.Index - 1] = L2_Buyer[sc.Index - 2];
		DI_Buyer[sc.Index - 1] = DI_Buyer[sc.Index - 2];        
        //LogString.Format("else. L2_Buyer[sc.Index - 1]: %.2f,  L2_Buyer[sc.Index - 2]: %.2f,  DI_Buyer[sc.Index - 1]: %.2f  DI_Buyer[sc.Index - 2]: %.2f", L2_Buyer[sc.Index - 1], L2_Buyer[sc.Index - 2], DI_Buyer[sc.Index - 1], DI_Buyer[sc.Index - 2]);
        //sc.AddMessageToLog("check 2 ", 0);

	}

    if (sc.Close[sc.Index - 1] < DC_High[sc.Index - 1], sc.Close[sc.Index - 2] >= DC_High[sc.Index - 2])
    {
        L2_Seller[sc.Index - 1] = sc.Close[sc.Index - 1];
        DI_Seller[sc.Index - 1] = DemandIndex[sc.Index - 1];
    }
    else
    {
        L2_Seller[sc.Index - 1] = L2_Seller[sc.Index - 2];
        DI_Seller[sc.Index - 1] = DI_Seller[sc.Index - 2];
    }



    //sc.AddMessageToLog(LogString, 0);
    /*SignalString.Format("L2_Buyer[-1]: %.2f,  L2_Buyer[-2]: %.2f, DI_Buyer[-1]: %.2f, DI_Buyer[-2]: %.2f, L2_Seller[-1]: %.2f, L2_Seller[-2]: %.2f, DI_Seller[-1]: %.2f, DI_Seller[-2]: %.2f",
        L2_Buyer[sc.Index - 1], L2_Buyer[sc.Index - 2], DI_Buyer[sc.Index - 1], DI_Buyer[sc.Index - 2], L2_Seller[sc.Index - 1], L2_Seller[sc.Index - 2], DI_Seller[sc.Index - 1] , DI_Seller[sc.Index - 2]);
    sc.AddMessageToLog(SignalString, 0);*/

}
Second one takes the "Accumulation Trading Algo" results as references to the subgraphs and proceeds straight into your trading system.

 
Code
SCSFExport scsf_msalem_Accumulation_V2(SCStudyInterfaceRef sc)
{
	//Inputs 
	///Imported studies subgraph(s) input arrays
	SCInputRef Input_Subgraph_L2_Buyer = sc.Input[0];
	SCInputRef Input_Subgraph_DI_Buyer = sc.Input[1];
	SCInputRef Input_Subgraph_L2_Seller = sc.Input[2];
	SCInputRef Input_Subgraph_DI_Seller = sc.Input[3];
	//General system inputs 
	SCInputRef Input_Enabled = sc.Input[4];
	SCInputRef Input_StartTime = sc.Input[5];
	SCInputRef Input_EndTime = sc.Input[6];
	//SCInputRef Input_FreeRange = sc.Input[5];
	SCInputRef Input_MaxPosition = sc.Input[7];
	SCInputRef Input_AttachedTradeWindowOrders = sc.Input[8];
	//Trading Targets, Stops 
	SCInputRef Input_Target1_margin = sc.Input[9];
	SCInputRef Input_Target2_margin = sc.Input[10];
	SCInputRef Input_Target3_margin = sc.Input[11];
	SCInputRef Input_Stopoffset = sc.Input[12];


	//Subgraphs 
	//Trading Subgraphs 
	SCSubgraphRef Subgraph_BuyEntry = sc.Subgraph[0];
	SCSubgraphRef Subgraph_SellEntry = sc.Subgraph[1];
	SCSubgraphRef Subgraph_BuyExit = sc.Subgraph[2];
	SCSubgraphRef Subgraph_SellExit = sc.Subgraph[3];
	//SCSubgraphRef Subgraph_DC_High = sc.Subgraph[4];

	// Set configuration variables

	if (sc.SetDefaults)
	{
		//Generic system defaults
		sc.GraphName = "MSalem Institutional Accumulation Trading Algo V2.0";
		sc.StudyDescription = "MSalem Institutional Accumulation Trading System";
		sc.GraphRegion = 0;
		sc.AutoLoop = 1;
		sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL;

		//Inputs' Arrays defaults

		//*SET/IMPORT* studies' subgraph(s)from the current chart: defaults to study 0, subgraph 0: change from the study settings to select the studies/subgraphs
		Input_Subgraph_L2_Buyer.Name = "L2_Buyer reference";
		Input_Subgraph_L2_Buyer.SetStudySubgraphValues(3, 0);

		Input_Subgraph_DI_Buyer.Name = "DI_Buyer reference";
		Input_Subgraph_DI_Buyer.SetStudySubgraphValues(3, 1);

		Input_Subgraph_L2_Seller.Name = "L2_Seller reference";
		Input_Subgraph_L2_Seller.SetStudySubgraphValues(3, 2);

		Input_Subgraph_DI_Seller.Name = "DI_Seller reference";
		Input_Subgraph_DI_Seller.SetStudySubgraphValues(3, 3);

		//General system input defaults
		Input_Enabled.Name = "Enabled";
		Input_Enabled.SetYesNo(1);

		Input_StartTime.Name = "Start Time";
		Input_StartTime.SetTime(0);

		Input_EndTime.Name = "End Time";
		Input_EndTime.SetTime(SECONDS_PER_DAY - 1);

		Input_MaxPosition.Name = "Max Position Allowed";
		Input_MaxPosition.SetInt(10);

		Input_AttachedTradeWindowOrders.Name = "Trade Window Orders";
		Input_AttachedTradeWindowOrders.SetYesNo(false);

		////Defaults for targets/stops
		Input_Target1_margin.Name = "Target1 offset";
		Input_Target1_margin.SetInt(20);
		Input_Target2_margin.Name = "Target2 offset";
		Input_Target2_margin.SetInt(10);
		Input_Target3_margin.Name = "Target3 offset";
		Input_Target3_margin.SetInt(5);
		Input_Stopoffset.Name = "Stop offset";
		Input_Stopoffset.SetInt(50);

		//Subgraphs' arrays defaults 

		Subgraph_BuyEntry.Name = "Buy Entry";
		Subgraph_BuyEntry.DrawStyle = DRAWSTYLE_ARROW_UP;
		Subgraph_BuyEntry.PrimaryColor = RGB(0, 255, 0);
		Subgraph_BuyEntry.LineWidth = 2;
		Subgraph_BuyEntry.DrawZeros = false;

		Subgraph_SellEntry.Name = "Sell Entry";
		Subgraph_SellEntry.DrawStyle = DRAWSTYLE_ARROW_DOWN;
		Subgraph_SellEntry.PrimaryColor = RGB(255, 0, 0);
		Subgraph_SellEntry.LineWidth = 2;
		Subgraph_SellEntry.DrawZeros = false;

		Subgraph_BuyExit.Name = "Buy Exit";
		Subgraph_BuyExit.DrawStyle = DRAWSTYLE_ARROW_DOWN;
		Subgraph_BuyExit.PrimaryColor = RGB(255, 128, 128);
		Subgraph_BuyExit.LineWidth = 2;
		Subgraph_BuyExit.DrawZeros = false;

		Subgraph_SellExit.Name = "Sell Exit";
		Subgraph_SellExit.DrawStyle = DRAWSTYLE_ARROW_UP;
		Subgraph_SellExit.PrimaryColor = RGB(128, 255, 128);
		Subgraph_SellExit.LineWidth = 2;
		Subgraph_SellExit.DrawZeros = false;

		/*Subgraph_DC_High.Name = "DC_High";
		Subgraph_DC_High.DrawStyle = DRAWSTYLE_LINE;
		Subgraph_DC_High.PrimaryColor = RGB(128, 255, 128);
		Subgraph_DC_High.LineWidth = 2;
		Subgraph_DC_High.DrawZeros = true;*/


		//Trading variables defaults: can switch to system input.

		// Only 1 trade for each Order Action type is allowed per bar.
		sc.AllowOnlyOneTradePerBar = true;
		sc.AllowEntryWithWorkingOrders = true;
		sc.AllowMultipleEntriesInSameDirection = true;
		//sc.CancelAllOrdersOnEntriesAndReversals = false;
		sc.AllowOppositeEntryWithOpposingPositionOrOrders = true;
		sc.SupportReversals = true;
		sc.CancelAllOrdersOnReversals = true;
		//sc.MaximumPositionAllowed = Input_MaxPosition.GetInt();
		// This is false by default. Orders will go to the simulation system always.
		sc.SendOrdersToTradeService = false;
		sc.SupportAttachedOrdersForTrading = true;
		//sc.UseGUIAttachedOrderSetting = true;
		// This line can be within sc.SetDefaults or outside of it.
		//sc.TradeWindowConfigFileName = "Test_2.twconfig";
		sc.CancelAllWorkingOrdersOnExit = true;
		//This needs to be set to true when a trading study uses trading functions.
		sc.MaintainTradeStatisticsAndTradesData = true;

		return;
	}

	// SYSTEM DATA Processing 

	//Setup for data processing 

	// **Get/IMPORT the array of the set studies(s) and corresponding subgraphs**

	SCFloatArray L2_Buyer;
	sc.GetStudyArrayUsingID(Input_Subgraph_L2_Buyer.GetStudyID(), Input_Subgraph_L2_Buyer.GetSubgraphIndex(), L2_Buyer);


	SCFloatArray DI_Buyer;
	sc.GetStudyArrayUsingID(Input_Subgraph_DI_Buyer.GetStudyID(), Input_Subgraph_DI_Buyer.GetSubgraphIndex(), DI_Buyer);

	SCFloatArray L2_Seller;
	sc.GetStudyArrayUsingID(Input_Subgraph_L2_Seller.GetStudyID(), Input_Subgraph_L2_Seller.GetSubgraphIndex(), L2_Seller);

	SCFloatArray DI_Seller;
	sc.GetStudyArrayUsingID(Input_Subgraph_DI_Seller.GetStudyID(), Input_Subgraph_DI_Seller.GetSubgraphIndex(), DI_Seller);


	// Get/IMPORT Inputs of selected studies ---Ex: the end Time for H/L study
   // int EndTimeInput;
   // sc.GetChartStudyInputInt(sc.ChartNumber, Input_Subgraph_HighofDay.GetStudyID(), 1, EndTimeInput);
	// Get the time of the bar at the current index
	int CurrentBarTime = sc.BaseDateTimeIn[sc.Index].GetTimeInSeconds();
	sc.MaximumPositionAllowed = Input_MaxPosition.GetInt();
	//bool TradingAllowed = Input_StartTime.GetTime() <= CurrentBarTime <= Input_EndTime.GetTime();


	// last close price array
	SCFloatArrayRef Last = sc.Close;
	//structure to hold all position data 
	s_SCPositionData PositionData;
	sc.GetTradePosition(PositionData);
	// declare string to print log messages
	SCString SignalString;
	SCString LogString;
	//// Use persistent variables to remember attached order IDs so they can be modified or canceled. 
	int32_t& Target1OrderID = sc.GetPersistentInt(1);
	int32_t& Stop1OrderID = sc.GetPersistentInt(2);

	// Process once per bar
	int& LastBarIndexProcessed = sc.GetPersistentInt(11);
	if (sc.Index == 0)
		LastBarIndexProcessed = -1;
	if (sc.Index == LastBarIndexProcessed)
		return;
	LastBarIndexProcessed = sc.Index;


	//
	///***************
	if (!Input_Enabled.GetYesNo())
		return;
	if (sc.IsFullRecalculation)
		return;


	// Create an s_SCNewOrder object. 



	s_SCNewOrder NewOrder;
	NewOrder.OrderQuantity = 1;
	NewOrder.OrderType = SCT_ORDERTYPE_STOP_LIMIT;;
	NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;


	/// Trading Logic 

	if (Input_StartTime.GetTime() < CurrentBarTime && Input_EndTime.GetTime() > CurrentBarTime)
	{

		//////BUY ENTIRES *************

		// If closed above the level high and no orders and no position, enter 3 limit buy orders at level high, mid-range, level low	
	   // if (  sc.FormattedEvaluate(sc.Close[sc.Index], sc.BaseGraphValueFormat, GREATER_OPERATOR, Input_Subgraph_HighofDay[sc.Index], sc.BaseGraphValueFormat) && 
		//sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && PositionData.PositionQuantityWithAllWorkingOrders == 0 && PositionData.PositionQuantity <=0)
		if (L2_Buyer[sc.Index - 1] != L2_Buyer[sc.Index - 2] &&
			L2_Buyer[sc.Index - 1] < L2_Buyer[sc.Index - 2] &&
			DI_Buyer[sc.Index - 1] > DI_Buyer[sc.Index - 2]
			)


		{
			//Buy Entry. Attached orders defined on Trade Window will be used.

			//1st order
			//define the Stop limit entry for order 1 

			NewOrder.Price1 = sc.High[sc.Index - 1] + 1 * sc.TickSize;

			//when not used the trade window attached orders then use the target stop attached orders margins from the level high otherwise use trade window attached orders 
			if (!Input_AttachedTradeWindowOrders.GetYesNo())
			{
				NewOrder.Target1Offset = Input_Target1_margin.GetInt() * sc.TickSize;
				NewOrder.Stop1Offset = Input_Stopoffset.GetInt() * sc.TickSize;
				NewOrder.OCOGroup1Quantity = 1;
			}

			int Result = (int)sc.BuyEntry(NewOrder);
			if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar.
			{
				Subgraph_BuyEntry[sc.Index - 1] = sc.Low[sc.Index - 1];
				SignalString.Format("Buy Stop Limit 1: %.2f & Buy Target1: %.2f & CurrentBarTime: %d & Max Position Allowed: %d", NewOrder.Price1, NewOrder.Price1 + NewOrder.Target1Offset, CurrentBarTime, Input_MaxPosition.GetInt());
				sc.AddMessageToLog(SignalString, 0);

			}
		}




		// SELL ENTRIES ******
		// Sell when the last price crosses the moving average from above.
		//else if (sc.CrossOver(sc.Close, Input_Subgraph_LowofDay) == CROSS_FROM_TOP && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
		//else if (sc.Close < Input_Subgraph_LowofDay[sc.Index] && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && PositionData.PositionQuantity == 0)	
		//else if (  sc.FormattedEvaluate(sc.Close[sc.Index], sc.BaseGraphValueFormat, LESS_OPERATOR, Input_Subgraph_LowofDay[sc.Index], sc.BaseGraphValueFormat) && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && PositionData.PositionQuantityWithAllWorkingOrders == 0 && PositionData.PositionQuantity >=0)
		else if (
			L2_Seller[sc.Index - 1] != L2_Seller[sc.Index - 2] &&
			L2_Seller[sc.Index - 1] > L2_Seller[sc.Index - 2] &&
			DI_Seller[sc.Index - 1] < DI_Seller[sc.Index - 2]
			)

		{
			//Sell Entry. Attached orders defined on Trade Window will be used.
			//1st order 

			NewOrder.Price1 = sc.Low[sc.Index - 1] - 1 * sc.TickSize;


			if (!Input_AttachedTradeWindowOrders.GetYesNo())
			{
				NewOrder.Target1Offset = Input_Target1_margin.GetInt() * sc.TickSize;
				NewOrder.Stop1Offset = Input_Stopoffset.GetInt() * sc.TickSize;
				NewOrder.OCOGroup1Quantity = 1;
			}
			int Result = (int)sc.SellEntry(NewOrder);
			if (Result > 0) //If there has been a successful order entry, then draw an arrow at the high of the bar.
			{
				Subgraph_SellEntry[sc.Index - 1] = sc.High[sc.Index - 1];
				SignalString.Format("Sell Stop Limit 1: %.2f & Sell Target1: %.2f & CurrentBarTime: %d", NewOrder.Price1, NewOrder.Price1 - NewOrder.Target1Offset, CurrentBarTime);
				sc.AddMessageToLog(SignalString, 0);
			}
		}
	}
}
Seems to be working correctly but let me know. With the added advantage of not having the below code block stopping the first study from working only with replay/live.
 
Code
if (!Input_Enabled.GetYesNo())
		return;
	if (sc.IsFullRecalculation)
		return;

2021-01-02 11_45_43-Window


2021-01-02 11_46_50-Window


2021-01-02 11_47_19-Window

Follow me on Twitter Started this thread Reply With Quote
Thanked by:
  #45 (permalink)
mosalem2003
Toronto
 
Posts: 103 since Apr 2019
Thanks Given: 106
Thanks Received: 23

Thanks a lot for your elaborated and detailed code. This is highly appreciated and I will try it once back from the holiday. Happy new year ..

Sent using the NexusFi mobile app

Reply With Quote
  #46 (permalink)
mosalem2003
Toronto
 
Posts: 103 since Apr 2019
Thanks Given: 106
Thanks Received: 23



Thanks a lot for the great and excellent help. I have tried it now on SC...
There is still events where L2_Buyer and L2_Seller is not printed as I assumed. You can plot L2_Buyer and L2_Seller on the main chart with the Donchian Channel...
L2_Buyer should change when we close below the Donchian Channel Low at Index-2 and we close above it at Index-1 ..
L2_Seller should change when we close above the DC high at index-2 and close below it at Index-1 ...
I have shown in this image two events where the conditions are met but there is no change for L2_Buyer or L2_Seller , this was my main issue since the first version where I was importing all the subgraphs in one study... Is this expected behavior ?

Reply With Quote
  #47 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360

That should now be easy to debug. Un-comment the message log code in the "Accumulation Trading Algo" study and slowly run through it in replay checking what values you have printed to the log.

You will see exactly what each value is being used to figure out why it hasn't triggered as you suspected.

Follow me on Twitter Started this thread Reply With Quote
  #48 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360

Just checked that "Accumulation Trading Algo" study and its throwing the correct signals so I would now check the values at the trading system study to see if the values in the Trading logic are correct. This block,

 
Code
if (L2_Buyer[sc.Index - 1] != L2_Buyer[sc.Index - 2] &&
			L2_Buyer[sc.Index - 1] < L2_Buyer[sc.Index - 2] &&
			DI_Buyer[sc.Index - 1] > DI_Buyer[sc.Index - 2]
			)
as well as this,
 
Code
if (Input_StartTime.GetTime() < CurrentBarTime && Input_EndTime.GetTime() > CurrentBarTime)
2021-01-03 18_54_19-Window

Follow me on Twitter Started this thread Reply With Quote
  #49 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360

Ok. I think its working correctly @mosalem2003 just spent 15 min banging this together and checking seems to fire when it should, though I don't know what setting you have on your study to replicate the exact example you posted. So I'll leave it to you to debug but to help paste this in your trading system study to see what conditions are true/false and whats causing what you thing is an error.

just below the process once per bar code block,

 
Code
	SCString& Long1 = sc.GetPersistentSCString(1);
	SCString& Long2 = sc.GetPersistentSCString(2);
	SCString& Long3 = sc.GetPersistentSCString(3);
	SCString& Short1 = sc.GetPersistentSCString(4);
	SCString& Short2 = sc.GetPersistentSCString(5);
	SCString& Short3 = sc.GetPersistentSCString(6);



	if (L2_Buyer[sc.Index - 1] != L2_Buyer[sc.Index - 2])
	{
		Long1 = "True";
	}
	else {
		Long1 = "False";
	}
	if (L2_Buyer[sc.Index - 1] < L2_Buyer[sc.Index - 2])
	{
		Long2 = "True";
	}
	else {
		Long2 = "False";
	}
	if (DI_Buyer[sc.Index - 1] > DI_Buyer[sc.Index - 2])
	{
		Long3 = "True";
	}
	else {
		Long3 = "False";
	}

	if (L2_Seller[sc.Index - 1] != L2_Seller[sc.Index - 2])
	{
		Short1 = "True";
	}
	else {
		Short1 = "False";
	}
	if (L2_Seller[sc.Index - 1] > L2_Seller[sc.Index - 2])
	{
		Short2 = "True";
	}
	else {
		Short2 = "False";
	}
	if (DI_Seller[sc.Index - 1] < DI_Seller[sc.Index - 2])
	{
		Short3 = "True";
	}
	else {
		Short3 = "False";
	}

	LogString.Format("Long1: %s, Long2: %s, Long3: %s  |  Short1: %s, Short2: %s, Short3: %s", Long1.GetChars(), Long2.GetChars(), Long3.GetChars(), Short1.GetChars(), Short2.GetChars(), Short3.GetChars());
	sc.AddMessageToLog(LogString, 0);

Follow me on Twitter Started this thread Reply With Quote
  #50 (permalink)
mosalem2003
Toronto
 
Posts: 103 since Apr 2019
Thanks Given: 106
Thanks Received: 23


Thanks a lot @Trembling Hand... I will check it accordingly. My main concern was how the ( Trading Algo study ) subgraphs L2_Buyer/Seller perform. I use DC channel 30 minutes and also Demand Index 30 minutes.
However it's time frame independent. When price closed at the last bar above the Dochian Low and closed below it the past bar , then L2_Buyer should equal the last closed price .... Similarly, when price closed below the Dochian High at the last bar and closed above it the past bar then L2_Seller will equal the last bar close. This is the main concern. I will check given your modification to the trading system code if it would impact the trading algo study subgraph calculations? I assumed they are independent but I will have to check it once at my desk and inform you.. Thanks a lot for your great help and continuous education...

Sent using the NexusFi mobile app

Reply With Quote




Last Updated on April 23, 2024


© 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