<?xml version="1.0" encoding="utf-8"?>

<Strategy xmlns="http://www.fixprotocol.org/FIXatdl-1-1/Core"
    xmlns:val="http://www.fixprotocol.org/FIXatdl-1-1/Validation"
    xmlns:lay="http://www.fixprotocol.org/FIXatdl-1-1/Layout"
    xmlns:flow="http://www.fixprotocol.org/FIXatdl-1-1/Flow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.fixprotocol.org/FIXatdl-1-1/Core tt-fixatdl-core-1-1.xsd"
    name="TT_Timed" uiRep="TT Timed" version="15.115.13" providerID="TT" entryFile="algo.so">

    <HideFromUIComponents>
        <UIComponent>Dashboard</UIComponent>
    </HideFromUIComponents>

    <Parameter name="__instr_id" xsi:type="String_t" refValue="OrderInstrumentID" required="true" dir="In" updateable="false"/>

    <Parameter name="__order_quantity" xsi:type="Qty_t" refValue="OrderQty" required="true" dir="In" updateable="true"/>

    <Parameter name="__price" xsi:type="Price_t" refValue="OrderPrice"  required="true" dir="In" updateable="true"/>

    <Parameter name="__side" xsi:type="Int_t" refValue="OrderSide"  required="true" dir="In" updateable="false"/>

    <Parameter name="__account" xsi:type="String_t" refValue="OrderAccount"  required="true" dir="In" updateable="false"/>

    <Parameter name="ParentTIF" xsi:type="Int_t" initValue="eDay" required="true" dir="In" updateable="false" orderEntryFixtag="16950">
        <EnumPair enumID="eGTC" wireValue="2"/>
        <EnumPair enumID="eDay" wireValue="1"/>
        <EnumPair enumID="eTime" wireValue="7"/>
    </Parameter>

    <Parameter name="ChildTIF" xsi:type="Int_t" refValue="OrderTif" required="true" dir="In" updateable="false" orderEntryFixtag="16903"/>

    <!-- Order type -->
    <Parameter name="__type" xsi:type="Int_t" initValue="eLimit" required="true" dir="In" updateable="false">
        <EnumPair enumID="eMkt" wireValue="1"/>
        <EnumPair enumID="eLimit" wireValue="2"/>
        <EnumPair enumID="eMLM" wireValue="21"/>
    </Parameter>

    <Parameter name="LimitTicksAway" xsi:type="Int_t" minValue="-999" maxValue="999" initValue="1" required="false" dir="In" updateable="true"  orderEntryFixtag="16912"/>

    <Parameter name="LimitPriceType" xsi:type="Int_t" initValue="eLtp" required="false" dir="In" updateable="false"  orderEntryFixtag="16911">
        <EnumPair enumID="eLtp" wireValue="3"/>
        <EnumPair enumID="eBid" wireValue="1"/>
        <EnumPair enumID="eAsk" wireValue="2"/>
        <EnumPair enumID="eSameSide" wireValue="6"/>
        <EnumPair enumID="eOppositeSide" wireValue="7"/>
    </Parameter>

    <!-- With a Tick -->
    <Parameter name="WithATickType" xsi:type="Int_t" initValue="eQty" required="false" dir="In" updateable="false" orderEntryFixtag="16921">
        <EnumPair enumID="eQty" wireValue="1"/>
        <EnumPair enumID="ePercent" wireValue="2"/>
    </Parameter>

    <Parameter name="WithATick" xsi:type="Qty_t" minValue="0.00000001" initValue="1" required="false" dir="In" updateable="true" orderEntryFixtag="16922"/>

    <!-- Date and Time -->
    <Parameter name="STime" xsi:type="UTCTimestamp_t" required="false" dir="In" updateable="true" orderEntryFixtag="168"/>

    <Parameter name="ETime" xsi:type="UTCTimestamp_t" required="false" dir="In" updateable="true" orderEntryFixtag="126"/>

    <Parameter name="ETimeAct" xsi:type="Int_t" required="false" dir="In" updateable="false" orderEntryFixtag="16906">
        <EnumPair enumID="eCancel" wireValue="1"/>
        <EnumPair enumID="eETAGoToMkt" wireValue="2"/>
    </Parameter>

  <Parameter name="ETAGoToMktTicksEnabled" xsi:type="Boolean_t" required="false" dir="In" updateable="true" initValue="false"/>
  <Parameter name="ETAGoToMktTicks"
               xsi:type="Int_t"
               initValue="10" minValue="0" maxValue="100"
               required="false" dir="In" updateable="true" orderEntryFixtag="16960"/>

    <Parameter name="AutoResubExpiredGTD" xsi:type="Boolean_t" initValue="false"  required="false" dir="In" updateable="false" orderEntryFixtag="16949"/>

    <Parameter name="WaitingOption" xsi:type="Int_t" initValue="eNow" required="true" dir="In" updateable="false" orderEntryFixtag="16961">
        <EnumPair enumID="eNow"        wireValue="0"/>
        <EnumPair enumID="eTime"       wireValue="1"/>
        <EnumPair enumID="ePreOpen" wireValue="2"/>
        <EnumPair enumID="eOpen"      wireValue="3"/>
    </Parameter>

    <lay:StrategyLayout>
        <lay:StrategyPanel>
            <lay:Control ID="TimedOrderLabel_1" xsi:type="lay:Label_t" label="Timed order details" class="atdl-panel-title"/>
            <lay:StrategyPanel name="ExchOrderTypePanel" orientation="HORIZONTAL">
                <lay:Control ID="ExchOrderType_ctrl" parameterRef="__type"
                    xsi:type="lay:DropDownList_t" initValue="eLimit" label="Exch order type">
                    <lay:ListItem enumID="eMkt" uiRep="Market"/>
                    <lay:ListItem enumID="eLimit" uiRep="Limit"/>
                    <lay:ListItem enumID="eMLM" uiRep="MLM order"/>
                </lay:Control>

                <lay:Control ID="Control_1" xsi:type="lay:HiddenField_t"> </lay:Control>
            </lay:StrategyPanel>
            <lay:StrategyPanel name="OffsetPanel" orientation="HORIZONTAL">
                <flow:StateRule visible="true">
                    <val:Edit field="ExchOrderType_ctrl" operator="NE" value="eMkt"/>
                </flow:StateRule>

                <lay:Control ID="Offset" label="Offset (ticks)" initValue="false"
                    xsi:type="lay:CheckBox_t"> </lay:Control>

                <lay:Control ID="PriceOffset_ctrl" parameterRef="LimitTicksAway"
                    xsi:type="lay:SingleSpinner_t">
                    <flow:StateRule visible="true">
                        <val:Edit field="Offset" operator="EQ" value="true"/>
                    </flow:StateRule>
                </lay:Control>
                <lay:Control ID="PriceOffsetType_ctrl" parameterRef="LimitPriceType"
                    xsi:type="lay:DropDownList_t">
                    <flow:StateRule visible="true">
                        <val:Edit field="Offset" operator="EQ" value="true"/>
                    </flow:StateRule>

                    <lay:ListItem enumID="eLtp" uiRep="LTP"/>
                    <lay:ListItem enumID="eBid" uiRep="Bid"/>
                    <lay:ListItem enumID="eAsk" uiRep="Ask"/>
                    <lay:ListItem enumID="eSameSide" uiRep="Same Side"/>
                    <lay:ListItem enumID="eOppositeSide" uiRep="Opposite Side"/>
                </lay:Control>
            </lay:StrategyPanel>

            <!-- With a Tick -->
            <lay:StrategyPanel name="WithATickPanel" orientation="HORIZONTAL">
                <flow:StateRule visible="true">
                    <val:Edit field="ExchOrderType_ctrl" operator="NE" value="eMkt"/>
                </flow:StateRule>

                <lay:StrategyPanel orientation="HORIZONTAL">
                <lay:Control ID="IsWithATick_ctrl" label="With a Tick" initValue="false"
                    xsi:type="lay:CheckBox_t"> </lay:Control>
                </lay:StrategyPanel>
                <lay:Control ID="WithATick_ctrl" parameterRef="WithATick"
                    xsi:type="lay:SingleSpinner_t">
                    <flow:StateRule visible="true">
                        <val:Edit field="IsWithATick_ctrl" operator="EQ" value="true"/>
                    </flow:StateRule>
                </lay:Control>
                <lay:Control ID="WithATickType_ctrl" parameterRef="WithATickType"
                    xsi:type="lay:DropDownList_t" initValue="eQty">
                    <flow:StateRule visible="true">
                        <val:Edit field="IsWithATick_ctrl" operator="EQ" value="true"/>
                    </flow:StateRule>
                    <lay:ListItem enumID="eQty" uiRep="Qty"/>
                    <lay:ListItem enumID="ePercent" uiRep="%"/>
                </lay:Control>
            </lay:StrategyPanel>
            <lay:Control ID="AutoResub"
                    label="Auto-Resubmit Upon GTD Expiry"
                    initValue="false"
                    parameterRef="AutoResubExpiredGTD"
                    xsi:type="lay:CheckBox_t" />
        </lay:StrategyPanel>

        <lay:StrategyPanel orientation="VERTICAL">
            <lay:Control ID="TimingSettingsLabel_1" xsi:type="lay:Label_t" label="Precondition details" class="atdl-panel-title"/>
            <!-- Start and End  Time -->
            <lay:StrategyPanel orientation="HORIZONTAL">
                <lay:StrategyPanel>
                    <lay:Control ID="Start_label" label="Start"
                                 xsi:type="lay:Label_t"/>
                </lay:StrategyPanel>
                <lay:Control ID="Start" xsi:type="lay:DropDownList_t" parameterRef="WaitingOption" column="3" initValue="eNow">
                    <lay:ListItem enumID="eNow" uiRep="Now"/>
                    <lay:ListItem enumID="eTime" uiRep="Time"/>
                    <lay:ListItem enumID="ePreOpen" uiRep="Pre-Open"/>
                    <lay:ListItem enumID="eOpen" uiRep="Open"/>
                </lay:Control>
                <lay:Control ID="StartTime_ctrl" parameterRef="STime" xsi:type="lay:Clock_t"
                             initValueMode="1">
                    <flow:StateRule visible="true">
                        <val:Edit field="Start" operator="EQ" value="eTime"/>
                    </flow:StateRule>
                </lay:Control>
            </lay:StrategyPanel>
            <lay:StrategyPanel orientation="HORIZONTAL">
                <lay:StrategyPanel>
                    <lay:Control ID="End_label" label="End"
                                 xsi:type="lay:Label_t"/>
                </lay:StrategyPanel>
                <lay:Control ID="End" xsi:type="lay:DropDownList_t" column="3" parameterRef="ParentTIF" initValue="eGTC">
                    <lay:ListItem enumID="eGTC" uiRep="GTC"/>
                    <lay:ListItem enumID="eTime" uiRep="Time"/>
                    <lay:ListItem enumID="eDay" uiRep="Day"/>
                </lay:Control>
                <lay:Control ID="EndTime_ctrl" parameterRef="ETime" xsi:type="lay:Clock_t"
                             initValueMode="1">
                    <flow:StateRule visible="true">
                        <val:Edit field="End" operator="EQ" value="eTime"/>
                    </flow:StateRule>
                </lay:Control>
            </lay:StrategyPanel>

            <lay:StrategyPanel name="EndTimeActionPanel">
                <!-- EndTimeActions -->
                <lay:StrategyPanel orientation="HORIZONTAL" indent="true">
                    <lay:Control ID="EndTimeAction_ctrl" parameterRef="ETimeAct"
                                    xsi:type="lay:DropDownList_t"
                                    initValue="eCancel"
                                    label="At End Action">
                        <lay:ListItem enumID="eCancel" uiRep="Cancel"/>
                        <lay:ListItem enumID="eETAGoToMkt" uiRep="GoToMarket"/>
                        <flow:StateRule visible="true">
                            <val:Edit field="End" operator="EQ" value="eTime"/>
                        </flow:StateRule>
                    </lay:Control>
                </lay:StrategyPanel>
                
                <!-- ETA GTM ticks -->
                <lay:StrategyPanel name="ETAGTMPanel" orientation="HORIZONTAL" indent="true">
                    <flow:StateRule visible="true">
                        <val:Edit logicOperator="AND">
                            <val:Edit field="End" operator="EQ" value="eTime"/>
                            <val:Edit field="EndTimeAction_ctrl" operator="EQ" value="eETAGoToMkt"/>
                        </val:Edit>
                    </flow:StateRule>
                  <lay:Control ID="etagtmTicksEnabled_ctrl" parameterRef="ETAGoToMktTicksEnabled" xsi:type="lay:CheckBox_t"
                               label="Mkt Order Lmt" initValue="false"/>
                  <lay:Control ID="etagtmTicks_ctrl" parameterRef="ETAGoToMktTicks" xsi:type="lay:SingleSpinner_t">
                    <flow:StateRule enabled="true">
                      <val:Edit field="etagtmTicksEnabled_ctrl" operator="EQ" value="true"/>
                    </flow:StateRule>
                  </lay:Control>
                  <lay:Control ID="ETAGTMTicks_label" xsi:type="lay:Label_t" label="ticks"/>
                </lay:StrategyPanel>
            </lay:StrategyPanel>
        </lay:StrategyPanel>
    </lay:StrategyLayout>

    <val:StrategyEdit errorMessage="Limit Offset must be between -999 and 999">
        <val:Edit logicOperator="OR">
            <val:Edit logicOperator="AND">
                <val:Edit field="__type" operator="NE" value="1"/>
                <val:Edit field="LimitTicksAway" operator="NE" value=""/>
                <val:Edit field="LimitTicksAway" operator="LE" value="999"/>
                <val:Edit field="LimitTicksAway" operator="GE" value="-999"/>
            </val:Edit>
            <val:Edit field="__type" operator="EQ" value="1"/>
            <val:Edit field="LimitTicksAway" operator="EQ" value=""/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="With a Tick quantity must be greater than 0">
        <val:Edit logicOperator="OR">
            <val:Edit field="WithATickType" operator="NE" value="1"/>
            <val:Edit logicOperator="AND">
                <val:Edit field="WithATickType" operator="EQ" value="1"/>
                <val:Edit field="WithATick" operator="NE" value=""/>
                <val:Edit field="WithATick" operator="GT" value="0"/>
            </val:Edit>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="With a Tick percentage must be positive">
        <val:Edit logicOperator="OR">
            <val:Edit field="WithATickType" operator="NE" value="2"/>
            <val:Edit logicOperator="AND">
                <val:Edit field="WithATickType" operator="EQ" value="2"/>
                <val:Edit field="WithATick" operator="NE" value=""/>
                <val:Edit field="WithATick" operator="GT" value="0"/>
            </val:Edit>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Start Time must precede End Time.">
        <val:Edit logicOperator="OR">
            <val:Edit field="STime" operator="EQ" value=""/>
            <val:Edit field="ETime" operator="EQ" value=""/>
            <val:Edit field="STime" operator="LT" field2="ETime"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Child time in force is not compatible with parent day order">
        <val:Edit logicOperator="OR">
            <val:Edit field="ParentTIF" operator="EQ" value="7"/>
            <val:Edit field="ParentTIF" operator="EQ" value="2"/>
            <val:Edit logicOperator="AND">
                <val:Edit field="ParentTIF" operator="EQ" value="1"/>
                <val:Edit logicOperator="OR">
                    <val:Edit field="ChildTIF" operator="EQ" value="1"/>
                    <val:Edit field="ChildTIF" operator="EQ" value="4"/>
                    <val:Edit field="ChildTIF" operator="EQ" value="5"/>
                </val:Edit>
            </val:Edit>
        </val:Edit>
    </val:StrategyEdit>

</Strategy>
