Skip to content

TryParse Method

TryParse

Summary

It parses a string and if it matched to a timeframe name it sets it to the passed timeFrame parameter

Signature

1
public static bool TryParse(string value, TimeFrame& timeFrame)

Parameters

Name Type Description
value string The timeframe name
timeFrame TimeFrame& The storage variable for the matching timeframe

Return Value

bool

Declaring Type

cAlgo.API.TimeFrame

Examples

1
2
 if (TimeFrame  < TimeFrame.Daily)
     Print("Intraday Trading");
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 using cAlgo.API;
 namespace cAlgo
 {
     // This sample indicator shows how to get a time frame from user via parameters and the get that time frame bars
     // Also you can use the pre-defined time frames
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class TimeFrameSample : Indicator
     {
         // Getting time frame via a parameter from user
         [Parameter("Time Frame", DefaultValue = "Daily")]
         public TimeFrame UserSelectedTimeFrame { get; set; }
         protected override void Initialize()
         {
             Print("Name: ", UserSelectedTimeFrame.Name, " | Short Name: ", UserSelectedTimeFrame.ShortName);
             // Getting another time frame bars data, using user selected time frame
             var barsBasedOnUserSelectedTimeFrame = MarketData.GetBars(UserSelectedTimeFrame);
             // Getting another time frame bars data, using pre-defined TimeFrames
             var barsBasedOnOtherTimeFrame = MarketData.GetBars(TimeFrame.Day2);
         }
         public override void Calculate(int index)
         {
         }
     }
 }

Last update: September 26, 2022

Comments