Login Page - Create Account

Support Board


Date/Time: Sat, 18 May 2024 22:45:52 +0000



learning to code a simple strategy

View Count: 2887

[2016-01-21 07:48:40]
User61576 - Posts: 418
i would be happy if i could be directed or instructed how run a simple strategy that buys on a specific date at 10:00 and has a stop of 1% and a target of 1% or flat by 15:30.
i would rather do this in the compiler and not in the spreadsheets so i will start learning how to use this

thanks
[2016-01-21 11:09:10]
Sierra Chart Engineering - Posts: 104368
Refer to the documentation here:
https://www.sierrachart.com/index.php?page=doc/doc_ACSILTrading.html
https://www.sierrachart.com/index.php?page=doc/doc_SCDateTime.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
[2016-01-24 22:27:19]
User61576 - Posts: 418
i could not understand from the 2nd link how to make a simple continuation criteria...
i would like to run a simple test on 1min bar chart according to the next rules

1. if yesterday was an up (down) day and
2. time of chart is 10:00
than execute a long trade (short)
3. close trade on end of session

thanks for your help!
[2016-01-24 23:40:50]
Sierra Chart Engineering - Posts: 104368
Please allow about a day for us to get documentation prepared for this.
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
[2016-01-25 05:12:51]
User61576 - Posts: 418
THANKS!
btw here is what i have done after reading the docs and took the example of the TradingExample1WithAdvancedAttachedOrders:


/*==========================================================================*/
SCSFExport scsf_TradingExample1WithAdvancedAttachedOrders(SCStudyInterfaceRef sc)
{
  // Define references to the Subgraphs and Inputs for easy reference
  SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0];
  SCSubgraphRef SellEntrySubgraph = sc.Subgraph[2];
  SCSubgraphRef SimpMovAvgSubgraph = sc.Subgraph[4];

  //settings that can be changed from within study settings in SC
  SCInputRef Enabled = sc.Input[0];
  SCInputRef Target1_percentage = sc.Input[1];
  SCInputRef Target2_percentage = sc.Input[2];
  SCInputRef stop_percentage = sc.Input[3];
  SCInputRef entry_hour = sc.Input[4];
  SCInputRef exit_hour = sc.Input[5];
  SCInputRef contracts = sc.Input[6];


  if (sc.SetDefaults)
  {
    // Set the study configuration and defaults.

    sc.GraphName = "Trading ADI With Advanced Attached Orders";

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

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

    SimpMovAvgSubgraph.Name = "Simple Moving Average";
    SimpMovAvgSubgraph.DrawStyle = DRAWSTYLE_LINE;
    SimpMovAvgSubgraph.PrimaryColor = RGB(255,255,0);
    SimpMovAvgSubgraph.LineWidth = 2;
    SimpMovAvgSubgraph.DrawZeros = false;

    Enabled.Name = "Enabled";
    Enabled.SetYesNo(0);

    sc.StudyDescription = "TEST. This study will do nothing until the 'Enabled' Input is set to Yes.";

    sc.AllowMultipleEntriesInSameDirection = false;
    sc.MaximumPositionAllowed = 1;
    sc.SupportReversals = false;

    // This is false by default. Orders will go to the simulation system always.
    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 = false;

    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;

    sc.AutoLoop = 1;
    sc.GraphRegion = 0;

    // During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;

    return;
  }

  if (!Enabled.GetYesNo())
    return;


  SCFloatArrayRef Last = sc.Close;


  // Calculate the moving average
  // sc.SimpleMovAvg(Last, SimpMovAvgSubgraph, sc.Index, 10);


  // Create an s_SCNewOrder object.
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = contracts;
  NewOrder.OrderType = SCT_ORDERTYPE_MARKET;

  //~Define the Attached Orders to be attached to the main Market order
  //TODO Target 1 - need to adjust according to the entry price * target1_percentage
  NewOrder.Target1Offset = sc.GetOrderFillEntry()*(1+target1_percentage);
  NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;

  //~Target 2
  NewOrder.Target1Offset = sc.GetOrderFillEntry()*(1+target2_percentage);
  NewOrder.AttachedOrderTarget2Type = SCT_ORDERTYPE_LIMIT;

  //~Common Step Trailing Stop
  //TODO - set a trailing according to the stop_percentage
  NewOrder.StopAllOffset = sc.GetOrderFillEntry()*(1-stop_percentage);
  NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_STEP_TRAILING_STOP_LIMIT;
  //problem???? how to set the updated leg as the stop % from the first target
  NewOrder.TrailStopStepPriceAmount = (sc.GetOrderFillEntry()*(1+target1_percentage)) -;

  // Common Trailing Stop. Comment the section above and uncomment this section to use a simple trailing stop.
  //NewOrder.StopAllOffset = 8*sc.TickSize;
  //NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_TRAILING_STOP;
  
  //TODO buy if time is 10:00 and yesterdays close was positive
  if (get.time= 10:00) && sc.GetBar(?????????) > 0)
  {
    int Result = sc.BuyEntry(NewOrder);
    if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar.
    {
      BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index];
    }
  }


  // Sell when the time is 10:00 and yesterday's close is negative
  else if (if (time= 10:00) && sc.GetBar(?????????) < 0)
  {
    int Result = sc.SellEntry(NewOrder);
    if (Result > 0) //If there has been a successful order entry, then draw an arrow at the high of the bar.
    {
      SellEntrySubgraph[sc.Index] = sc.High[sc.Index];

    }
  }
  //Problem: how do i add flat at end of day?
}

Date Time Of Last Edit: 2016-01-25 05:37:41
[2016-01-27 10:23:17]
Sierra Chart Engineering - Posts: 104368
Here is an example which can be used to take action at a particular time. It relies upon a function call which will be out in the next release coming out later today.

SCSFExport scsf_ActionWhenTimeEncountered(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    
    sc.GraphName = "Action When Time is Encountered";
    
    sc.StudyDescription = "This study function demonstrates performing an action when a certain time is encountered in the most recent chart bar.";
    
    sc.AutoLoop = 1;
    
    sc.FreeDLL = 0;
    
    return;
  }

  
  // Do data processing

  SCDateTime TimeToCheckFor;

  //The first step is to get the current date.
  int CurrentDate = sc.BaseDateTimeIn[sc.ArraySize - 1].GetDate();

  //Apply the time. For this example we will use 12 PM
  TimeToCheckFor.SetDate(CurrentDate);
  TimeToCheckFor.SetTimeHMS(12, 0, 0);

  // TimeToCheckFor is contained within the current bar.
  if (sc.IsDateTimeContainedInBarIndex(TimeToCheckFor, sc.Index))
  {
    //perform the action here
  }
  
}

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
[2016-01-29 13:53:17]
User61576 - Posts: 418
ok. got this part of time and added it to my code.

another q.
i want my stop order (attached) to be % based on the entry price
which method is better as from what i am reading both will get me the same? am i correct?

this

SCInputRef stop_percentage = sc.Input[3];

NewOrder.StopAllOffset = sc.GetOrderFillEntry()*(1-stop_percentage);

or this


SCInputRef stop_percentage = sc.Input[3];

NewOrder.StopAllOffset = myPositionData.AveragePrice*(1-stop_percentage);
?
[2016-01-29 17:57:03]
Sierra Chart Engineering - Posts: 104368
Neither of these will work. The price has to be set at the time the main order is sent. You cannot later add a Stop order in this way.

If you do, it has to be an independent order, not attached, and the parent order needs to be sent on its own.

The best way to get the fill price of the order is to use:
https://www.sierrachart.com/index.php?page=doc/doc_ACSILTrading.html#GetOrderByOrderID

There is a LastFillPrice member of the data structure that is filled in. You just need to remember the order ID of the parent order after it has been sent. The code example referred to shows just how to do this.
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: 2016-01-29 17:59:23
[2016-02-02 04:25:36]
Sierra Chart Engineering - Posts: 104368
Here is the documentation for the code example:
http://www.sierrachart.com/index.php?page=doc/doc_ACSILProgrammingConcepts.html#ActionWhenCertainTimeIsEncounteredInMostRecentBar
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
[2016-02-06 20:01:24]
User61576 - Posts: 418
1. as part of the code i wanted to use the perior daily close as a parameter.
i understood that i will need to use the overlay indicator and read this http://www.sierrachart.com/index.php?page=doc/doc_StudyPriceOverlayStudy.php
when applying it over my 1min chart, i have an issue that the daily data is not showed on the same time of the day. i would expect it to be on the first 1 of the day
i am attaching my settings of the study and my result of the chart

2. later, in my code i will refer to the close of the day before if to go long or short (if close[-1] > open [-1] than buy
after reading the guide here http://www.sierrachart.com/index.php?page=doc/doc_ACSILRefOtherTimeFrames.php
i am still don't understand how to make a simple calc of close vs open as the example is more confuing.
do i need to add this line
SCInputRef DailyClose = sc.Input[7];
to the head of the script? that's how i manually set parameters from the settings box ?

SCFloatArray Study1Array;
sc.GetStudyArrayUsingID(Study1.GetStudyID(),Study1Subgraph.GetSubgraphIndex(),Study1Array);
how do i get close and open from the study overlay?

bottom line after putting a lot of time reding again and again, i still don't understand ho to use this in ACSIL.

thanks for clearing this for me!
Date Time Of Last Edit: 2016-02-06 21:11:43
imageoverlay problem.jpg / V - Attached On 2016-02-06 19:57:39 UTC - Size: 315.38 KB - 364 views
imageoverlay settings.jpg / V - Attached On 2016-02-06 19:57:49 UTC - Size: 349.81 KB - 316 views
[2016-02-08 09:26:44]
Sierra Chart Engineering - Posts: 104368
Please understand we cannot provide programming help.

If you need help, you will need to contact one of the programmers here:
https://www.sierrachart.com/index.php?page=doc/SierraChartStudyAndSystemProgrammers.html

Or refer to the many code examples of the built-in Sierra Chart studies. For instructions refer to:
https://www.sierrachart.com/index.php?page=doc/doc_BuildCustomStudiesDLL.html

Although after reading this, this is a function that you may want to use to simplify what you are doing:
https://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_Functions.html#scGetOHLCForDate
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: 2016-02-08 09:41:55
[2016-02-08 10:46:21]
User61576 - Posts: 418
I understand about the progrraming.
can you please provdie help to the overlay study?
[2016-02-09 00:34:39]
Sierra Chart Engineering - Posts: 104368
Refer to the documentation here for the Study/Price Overlay study:
https://www.sierrachart.com/index.php?page=doc/doc_StudyPriceOverlayStudy.php

If you still have a problem we need to see chart images of both the source and destination charts. Here are instructions:
https://www.sierrachart.com/index.php?page=PostingInformation.php#Image
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
[2016-02-09 10:38:39]
Sierra Chart Engineering - Posts: 104368
Here is a chart image showing overlaying Daily bars on an Intraday chart:
http://www.sierrachart.com/image.php?l=1455009822290.png

It shows all of the Input settings being used.
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
[2016-02-10 06:13:58]
User61576 - Posts: 418
that's what i would expect. yet, here is my study again, which shows mid day bars as for the study overlay
hers is the daily chart http://www.sierrachart.com/image.php?l=1455084542690.png
here is the 1 min chart with overlays http://www.sierrachart.com/image.php?l=1455084595656.png where you can see there are bars in the middle of the day and if i use daily bars as the source this should not happen
thanks
[2016-02-11 04:38:34]
Sierra Chart Engineering - Posts: 104368
Make sure you are using the same Inputs settings that we are using in the example chart image. There is not a match of the Inputs to the example we gave.

We also see the daily chart is built from Intraday data which can also cause some odd behavior.

Use a Historical Daily chart.
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

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

Login

Login Page - Create Account