TradeStation Sample Code

Provided by Samuel K. Tennis (www.vista-research.com) - SKTennis@vista-research.com

 

Mr. Tennis is providing support for MTS for all TradeStation users. Mr. Tennis and I have been working together for over 10 years and I trust in his ability to provide the best support for all TradeStation users. Should you have any questions or want your TS code professionally converted to run with MTS, please contact Samuel K. Tennis.

 


{
Type : Strategy
Name : MENT Trader Services
Notes : Matheny Enterprises, sample using "MENT Trader Services" DLL

EasyLanguage translation provided
  for Brad Matheny
  of Matheny Enterprises
  by Samuel K. Tennis
  of Vista-Research (c) 2006

Any unauthorized use of this material may constitute
a violation of U.S. and International Copyright Laws.
}

Vars : App_Name ("MENT Trader Services") ;

// DLL Definitions for TradeStation 8.xx
external : "mentts.dll", int, "placeorder", string, string, string, string, int, double, string, string, string, string, double ;
external : "mentts.dll", int, "cancel", string, int ;
external : "mentts.dll", int, "getfillamount", string, int ;
external : "mentts.dll", double, "getfillprice", string, int ;
external : "mentts.dll", string, "getstatus", string, int ;
external : "mentts.dll", int, "getbrokers" ;
external : "mentts.dll", int, "getcurrentposition", string, string ;


if (@BarNumber <= 01) then begin
end ; { first bar of data }

if (Date [00] > Date [01]) then begin
end ; { first bar of new day }

//If marketposition < +01 then Buy ("le.Main") this bar at close ;
//If marketposition = +01 then sell short ("se.Main") this bar at close ;

Vars : GAINMultiplier (100000),
       DefEntryContracts (01),
       LEntryOrderID (00) ;
Vars : GetCurPos (00) ;


if (Date = @vrt.LastCalcDate) and ( Time = @vrt.LastCalcTime)
then begin

  LEntryOrderID = PlaceOrder ("GAIN", "BUY", "MARKET", "GBP/USD", (GAINMultiplier * DefEntryContracts),0, "GTC", "", "", "", 0) ;
  if (LEntryOrderID < 00) then begin
    Print ("'", @GetSymbolName, "', ", @vrt.MMDDYYYY (Date), ", ", @vrt.HHMM.pm (Time), ", #", LEntryOrderID:1:2) ;
  end // threw an error...
  else Print ("Success : '", @GetSymbolName, "', ", @vrt.MMDDYYYY (Date), ", ", @vrt.HHMM.pm (Time), ", Order #", LEntryOrderID:1:2) ;

  GetCurPos = GetCurrentPosition ("GAIN", "GBP/USD") ;
  if (GetCurPos < -1000000000) then begin
    Print ("'", @GetSymbolName, "', ", @vrt.MMDDYYYY (Date), ", ", @vrt.HHMM.pm (Time), ", #", GetCurPos:1:2) ;
  end // threw an error...
  else
  if (GetCurPos > 00)
    then Print ("Success : '", @GetSymbolName, "', ", @vrt.MMDDYYYY (Date), ", ", @vrt.HHMM.pm (Time), ", Long #", GetCurPos:1:2)
  else
  if (GetCurPos < 00)
    then Print ("Success : '", @GetSymbolName, "', ", @vrt.MMDDYYYY (Date), ", ", @vrt.HHMM.pm (Time), ", Short #", GetCurPos:1:2)
  else Print ("Success : '", @GetSymbolName, "', ", @vrt.MMDDYYYY (Date), ", ", @vrt.HHMM.pm (Time), ", Flat #", GetCurPos:1:2) ;
end ;

{*
Vars : tx_Ref (-01),
       tx_Err (00) ;

tx_Ref = @Text_New (cDate, tTime, nPrice, str1) ;
tx_Err = @Text_SetStyle (tx_Ref, horiz, vert) ;
tx_Err = @Text_SetColor (tx_Ref, clr) ;
tx_Err = @Text_SetString (tx_Ref, str1) ;

Date-line = horizontal/x-coordinate
Hright  0    Drawn right of the date-line
Hleft   1    Drawn left of the date-line
Hcenter 2    Drawn centered on the date-line

Price-line = vertical/y-coordinate
Vbelow  0     Drawn below the price-line
Vabove  1     Drawn above the price-line
Vcenter 2     Drawn centered on the price-line
*}

if (@MarketPosition = +01) then begin
  if (@BarsSinceEntry <= 01) then begin
  end ; { first bar of trade }
end ; { currently long }

if (@MarketPosition = -01) then begin
  if (@BarsSinceEntry <= 01) then begin
  end ; { first bar of trade }
end ; { currently short }


#beginCmtry
Inputs: ShowCmtry (FALSE) ;

if CheckCommentary and ShowCmtry then begin
CommentaryCL ("Strategy : '", App_Name,
                        "' ", @vrt.MMDDYYYY (Date),
                        " ", @vrt.HHMM.pm (Time)) ;

end ; { expert commentary enabled for this bar }
#end ;

{
Custom Programming Services provided by:

Samuel K. Tennis
Vista-Research
129 Staff Drive, NE
Ft. Walton Beach, Florida 32548
voice : 1(850) 243-5105
fax : 1(510) 743-8274
eMail :sktennis@vista-research.com
http://www.vista-research.com
}