Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 08:51:08 +0000



ACSIL question

View Count: 2264

[2014-08-21 02:43:25]
User120827 - Posts: 77
hi

I have this in my code to flatten at end of session, courtesy of vegasfoster.

I would like to have it as an option on settings menu.
I was able to get the flatten part on the settings menu, but it is just a regular flatten command without the session times like the code below.

thanks


if (InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime)
  
    sc.FlattenAndCancelAllOrders();

[2014-08-21 06:34:28]
vegasfoster - Posts: 444
Not 100% sure this is what you are asking for, but try adding to sc.SetDefaults section,


sc.Input[#].Name = "Flatten and Cancel?";
sc.Input[#].SetCustomInputStrings("Yes;No");
sc.Input[#].SetCustomInputIndex(0);

then modify

if (InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime) && sc.Input[#].GetIndex() == 0)

substitute # with the next number in your sc.Input sequence.
Date Time Of Last Edit: 2014-08-21 06:36:14
[2014-08-21 06:52:35]
Sierra Chart Engineering - Posts: 104368
We can only refer you to the documentation here about this:

https://www.sierrachart.com/index.php?page=doc/doc_MouseAndMenuInteractionFromACStudy.html
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2014-08-21 11:47:05]
User120827 - Posts: 77
We can only refer you to the documentation here about this:

https://www.sierrachart.com/index.php?page=doc/doc_MouseAndMenuInteractionFromACStudy.html
Cheers

Why a link to mouse commands ?


[2014-08-21 14:59:49]
vegasfoster - Posts: 444
I think because you referred to "menu" it could read as if you want to customize the menus. That's why I wasn't sure either.
[2014-08-21 16:05:58]
Sierra Chart Engineering - Posts: 104368
Yes, it sounded like you wanted to add a custom menu item to the chart shortcut menu.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2014-08-21 16:06:08
[2014-08-21 17:24:27]
User021827 - Posts: 174
Hi

I see .
I thought you could add it to the settings portion of the study. I did not realize it was a custom menu item also.

I think I am used to the spreadsheet where so much is set under settings ! I am still thinking along those lines.


I just recently started to switch over to ACSIL, and I have minimal programming experience. Forgive my inexperience.

Should I learn to do it as a custom menu command ? Is that better in the long run ?

And thanks for your help also.


Date Time Of Last Edit: 2014-08-21 17:25:29
[2014-08-21 17:33:03]
Sierra Chart Engineering - Posts: 104368
You can add study Inputs to the Study Settings window. This is documented here:
https://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_scInputs.html

Adding menu commands is advanced and uncommon. It sounds like what you want is a Study Input and that is much simpler.


Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2014-08-21 18:34:17]
User021827 - Posts: 174
hi

yes , thanks for the link.

regards
Shane
[2014-08-21 20:20:37]
User120827 - Posts: 77
Hi
I recieved this error msg in compliler.. Did I forget something ?


error: label 'sc' used but not defined
if (InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime) && sc.Input[7].GetIndex() == 0)

regards

Date Time Of Last Edit: 2014-08-21 20:40:22
[2014-08-21 20:49:08]
User120827 - Posts: 77
Does anything stand out as wrong in this code ?

With the error I got compiling, it seems I forgot something when adding the extra code you gave me.
It seems I did not define something.

Does the "send order to trade service " item I added to settings menu look correct?

thanks




// The top of every source code file must include this line
#include "sierrachart.h"


/*****************************************************************************

  For reference, please refer to the Advanced Custom Study Interface
  and Language documentation on the Sierra Chart website.
  
*****************************************************************************/


// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("Go Live")


SCSFExport scsf_SC_TradingCrossOverExample(SCStudyGraphRef sc)
{

  SCInputRef Line1Ref = sc.Input[0];
  SCInputRef Line2Ref = sc.Input[1];
  SCInputRef Enabled = sc.Input[2];
  
  
  SCSubgraphRef BuyEntry = sc.Subgraph[0];
  SCSubgraphRef SellEntry = sc.Subgraph[1];
  
  
  SCInputRef SendOrdersToService = sc.Input[10];
  

  

  if (sc.SetDefaults)
  {

    // Set the configuration and defaults

    sc.GraphName = "Trading CrossOver Example";
    
    Enabled.Name = "Enabled";
    Enabled.SetYesNo(0);

    sc.StudyDescription = "An example .";

    sc.AutoLoop = 1; // true
    sc.GraphRegion = 0;
    sc.FreeDLL = 1;
    sc.CalculationPrecedence = LOW_PREC_LEVEL;
    
    sc.Input[3].Name = "Start Hour";
    sc.Input[3].SetInt(10);
    sc.Input[3].SetIntLimits(0,23);

    sc.Input[4].Name = "Start Minute";
    sc.Input[4].SetInt(0);
    sc.Input[4].SetIntLimits(0,59);

    sc.Input[5].Name = "End Hour";
    sc.Input[5].SetInt(16);
    sc.Input[5].SetIntLimits(0,23);

    sc.Input[6].Name = "End Minute";
    sc.Input[6].SetInt(0);
    sc.Input[6].SetIntLimits(0,59);

    Line1Ref.Name = "Line1";
    Line1Ref.SetStudySubgraphValues(1, 0);

    Line2Ref.Name = "Line2";
    Line2Ref.SetStudySubgraphValues(1, 0);

    BuyEntry.Name = "Buy";
    BuyEntry.DrawStyle = DRAWSTYLE_POINTHIGH;
    BuyEntry.LineWidth = 3;

    SellEntry.Name = "Sell";
    SellEntry.DrawStyle = DRAWSTYLE_POINTLOW;
    SellEntry.LineWidth = 3;
    
    sc.Input[7].Name = "Flatten and Cancel?";
    sc.Input[7].SetCustomInputStrings("Yes;No");
    sc.Input[7].SetCustomInputIndex(0);


    sc.AllowMultipleEntriesInSameDirection = false;
    sc.MaximumPositionAllowed = 5;
    sc.SupportReversals = true;

    // This is false by default. Orders will not go to the external connected trading service.
    sc.SendOrdersToTradeService = false;

    sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;

    // This can be false in this function because we specify Attached Orders directly with the order which causes this to be considered true when submitting an order.
    sc.SupportAttachedOrdersForTrading = true;

    sc.CancelAllOrdersOnEntriesAndReversals= true;
    sc.AllowEntryWithWorkingOrders = false;
    sc.CancelAllWorkingOrdersOnExit = true;

    // Only 1 trade for each Order Action type is allowed per bar.
    sc.AllowOnlyOneTradePerBar = true;

    //This needs to be set to true when a trading study uses trading functions.
    sc.MaintainTradeStatisticsAndTradesData = true;
    
    SendOrdersToService.Name = "Send Orders to Trade Service";
    SendOrdersToService.SetYesNo(false);


    return;
  }
  
  if (!Enabled.GetYesNo())
    return;

  // only process at the close of the bar; if it has not closed don't do anything
  if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED)
  {
    return;
  }
  
  int StartTime, EndTime, InputDate;
  SCDateTime StartDateTime, EndDateTime, InputDateTime1, InputDateTime2;

  InputDate = sc.BaseDateTimeIn[sc.Index].GetDate();
  InputDateTime1 = sc.BaseDateTimeIn[sc.Index];
  InputDateTime2 = sc.BaseDateTimeIn[sc.Index-1];

  StartTime = HMS_TIME(sc.Input[3].GetInt(), sc.Input[4].GetInt(), 0);
  StartDateTime = COMBINE_DATE_TIME(InputDate, StartTime);
  EndTime = HMS_TIME(sc.Input[5].GetInt(), sc.Input[6].GetInt(), 0);
  EndDateTime = COMBINE_DATE_TIME(InputDate, EndTime);
  
  {
  
  }

  // using the line1Ref and line2Ref input variables, retrieve the subgraph arrays into line1, line2 arrays respectively
  SCFloatArray line1;
  sc.GetStudyArrayUsingID(Line1Ref.GetStudyID(), Line1Ref.GetSubgraphIndex(), line1);

  SCFloatArray line2;
  sc.GetStudyArrayUsingID(Line2Ref.GetStudyID(), Line2Ref.GetSubgraphIndex(), line2);
  
   sc.SendOrdersToTradeService = SendOrdersToService.GetYesNo();

  // code
  if (InputDateTime1 > StartDateTime && InputDateTime1 < EndDateTime)
  if (sc.CrossOver(line1, line2) == CROSS_FROM_BOTTOM)
  {

    // mark the crossover on the chart
    BuyEntry[sc.Index] = 1;

    // Create a market order and enter long.
    s_SCNewOrder order;
    order.OrderQuantity = 1;
    order.OrderType = SCT_ORDERTYPE_MARKET;

    sc.BuyEntry(order);
  }
  if (InputDateTime1 > StartDateTime && InputDateTime1 < EndDateTime)
  if (sc.CrossOver(line1, line2) == CROSS_FROM_TOP)
  {


    // mark the crossover on the chart
    SellEntry[sc.Index] = 1;

    // create a market order and enter short
    s_SCNewOrder order;
    order.OrderQuantity = 1;
    order.OrderType = SCT_ORDERTYPE_MARKET;

    sc.SellEntry(order);
  }
   if (InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime) && sc.Input[7].GetIndex() == 0)
   sc.FlattenAndCancelAllOrders();
}

Date Time Of Last Edit: 2014-08-21 21:04:19
[2014-08-21 21:24:22]
crazybears - Posts: 314
if ((InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime) && sc.Input[7].GetIndex() == 0)

needs another ( after if ;-)
[2014-08-21 21:42:22]
User120827 - Posts: 77
hi

Thank you very much for spotting my error. I appreciate it. When I copied the code, I did not select it all properly I believe.

thanks again !

sincerely,
shane

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account