General Trading Chat

ap*

Well-Known Member
@Smart_trade @Happy_Singh @monkeybusiness @ap* : To all the Bros. My vaccation is kind of ruined ever since I onboarded myself to AmiB. Yesterday was awake till 2:30 am, and same seems to happen today. Converting one of my so called Long Only straegies into AmiB and backtesting. Need a small help. I want to keep my lot size fixed for backtesting. I saw the Backtesting setup window where I can change my parameter but unable to do what I want.

I want to keep my account size 20 Lakh and fixed lot size to 200 lot (crude mini). So there is a field for putting the amount depolyed but AmiB is changing the lot size automatically during each trigger in the backtest. Something like this. How can I fix this to 200?





Win rate was 50% as tested in my ealrier tool, but the result is coming sckewed due to variable position size which I want to avoid.



Sorry if I posted on a wrong thread. But my first encounter with Amib, so execuse me.
Tuna Sir no clue regarding backtest. Will let the others comment. I am new to Amibroker as well.
 

manojborle

Well-Known Member
Code:
_SECTION_BEGIN("Framework_Template");
/////////////////////////////////////////////////////////////////////
///////////////Start - Backtest Framework Parameters/////////////////
/////////////////////////////////////////////////////////////////////

//Init
    SetBarsRequired(10000,10000);

// Backtest settings
    //    Set AA options:
    //    Set Apply to = [Use Filter] Market = ASX, Exclude Indexes
    //    Set Range = 1/1/1997 to 1/1/2007

// Trading Style Parameters
    //    Set AA options:
    //    Set Positions = Long
    //    Set Periodicity = Daily

// Locked Comparison Parameters
    SetOption("InitialEquity", 100000 );
    SetOption("CommissionMode", 2 );
     SetOption("CommissionAmount", 30.00 );
    BuyPrice = High;
    SellPrice = Low;
    ShortPrice = Low;
    CoverPrice = High;
    
// Minimum method parameters
    SetTradeDelays(1,1,1,1);

// Trading method parameters
    SetOption("FuturesMode", False );
    SetOption("AllowSameBarExit", False );
    SetOption("AllowPositionShrinking", False );
    SetOption("ReverseSignalForcesExit", True );
    SetOption("PriceBoundChecking", True );
    SetOption("UsePrevBarEquityForPosSizing", False );
    
    RoundLotSize = 1;
    PositionSize = 5000;

// Portfolio Settings
    SetOption("MaxOpenPositions", 10 );
    //    Set AA options:
    //    Set Limit trade size as % of entry bar volume = 10
    //    Set Disable trade size limit when bar Volume is zero = False

/////////////////////////////////////////////////////////////////////
///////////////End - Backtest Framework Parameters///////////////////
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
///////////////Start - Trading method code///////////////////////////
/////////////////////////////////////////////////////////////////////
//
// System: EMaCross
//
/////////////////////////////////////////////////////////////////////

// Optimize Parameters
    Short_EMA_Var = Optimize("Short_EMA_Variable",6,1,10,1);
    Long_EMA_Var = Optimize("Long_EMA_Variable",73,30,100,1);

// Stock Selection
    //Buy only if PositionSize is 10% or less than 3 months average turnover.
    Turnover_Filter = (MA((Volume * C),60)*.10) > PositionSize;

    //Set the order for which stock trades when get mulitple signals in one bar in backtesting
    PositionScore = 100-RSI(); // prefer stocks that have low RSI;

// Signal
    Long_EMA = EMA( Close, Long_EMA_Var);
    Short_EMA = EMA( Close, Short_EMA_Var);

    Buy  = Cross( Short_EMA, Long_EMA ) AND Turnover_Filter;
    Sell = Cross( Long_EMA, Short_EMA );

// Cleanup signal
    Buy = ExRem(Buy,Sell);
    Sell = ExRem(Sell,Buy);
    

// Plot Price & Volume
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title = "EMACrossT " + Date() + " Open "+O+" Hi "+H+" Low "+L+" Close "+C+" Volume "+WriteVal(V,1) + "\nBase Index:" + GetBaseIndex() );

    Color = IIf(O > C, colorBlack, colorYellow);
    Plot( Close, "Price", color, styleCandle);
 
    BarColor =
        IIf( V > Ref(V,-1),  colorLightBlue , /* up volume */
        IIf( V < Ref(V,-1),  colorDarkBlue, /* down volume */
                     colorGreen /*otherwise*/ ));
    Plot( Volume, "Turnover", BarColor, styleHistogram | styleThick | styleOwnScale);

// Plot Raw signals
    Plot( Short_EMA, "Short_EMA", colorBlue, styleLine);
    Plot( Long_EMA, "Long_EMA", colorRed, styleLine);
    shape = Buy * shapeSmallCircle + Sell * shapeSmallCircle;
    PlotShapes( shape, IIf( Buy, colorLime , colorRed ),0);

// Display details for live trade explore
    Filter = (Buy OR Sell);
    AddTextColumn(WriteIf(Buy,"Buy","Sell"),"Buy/Sell");
    AddColumn(PositionScore,"Position");

/////////////////////////////////////////////////////////////////////
///////////////End - Trading method code/////////////////////////////
/////////////////////////////////////////////////////////////////////
_SECTION_END();
Tuna Sir
You can use afl like this for backtesting, you can see a tab in backtest settings window called portfolio, there is option to select custom backtest procedure.
screenshot_701.png
 

Tuna

Listen and act, don't ask it, it doesn't oblige
Thanks Manoj. Let me try this out
 

Tuna

Listen and act, don't ask it, it doesn't oblige
Found a easier solution, ctrl + A --> Ctrl C to excel, change the position size to consistent, LoL !! Thanks. Sorry for the mess here.
 

Tuna

Listen and act, don't ask it, it doesn't oblige
Someone kick me!!. Since last 2 hours making optimizations to AFL and testing another one. Good Night guys. Got to go to bed.
 
@Smart_trade @Happy_Singh @monkeybusiness @ap* : To all the Bros. My vaccation is kind of ruined ever since I onboarded myself to AmiB. Yesterday was awake till 2:30 am, and same seems to happen today. Converting one of my so called Long Only straegies into AmiB and backtesting. Need a small help. I want to keep my lot size fixed for backtesting. I saw the Backtesting setup window where I can change my parameter but unable to do what I want.

I want to keep my account size 20 Lakh and fixed lot size to 200 lot (crude mini). So there is a field for putting the amount depolyed but AmiB is changing the lot size automatically during each trigger in the backtest. Something like this. How can I fix this to 200?





Win rate was 50% as tested in my ealrier tool, but the result is coming sckewed due to variable position size which I want to avoid.



Sorry if I posted on a wrong thread. But my first encounter with Amib, so execuse me.

use this for fixed size of 100 Shares

Code:
SetPositionsize(100,4);
Ref: Amibroker Help file
SetPositionSize
- set trade size

Trading system toolbox
(AFL 2.70)


SYNTAX SetPositionSize( size, method )
RETURNS
ARRAY
FUNCTION This function allows to control trade (position) size in four different ways, depending on 'method' parameter.
Parameters:

size (ARRAY) defines desired trade size

method (ARRAY) defines how 'size' is interpreted

  • spsValue (=1) - dollar value of size (as in previous versions)
  • spsPercentOfEquity (=2) - size expressed as percent of portfolio-level equity (size must be from ..100 (for regular accounts) or .1000 for margin accounts)
  • spsShares (=4) - size expressed in shares/contracts (size must be > 0 )
  • spsPercentOfPosition (=3) - size expressed as percent of currently open position (for SCALING IN and SCALING OUT ONLY)
  • spsNoChange (=0) - don't change previously set size for given bar
Happy :)
 
Someone please suggest a way

How to convert .csv file into .txt file (with comma separated), like,
20170904,09:16:00,9983,9983.3,9953.45,9953.95,0
OR
To convert tab separated text file to comma separated text file, as above

What I am getting is tab separated
20170904 09:16:00 9983 9983.3 9953.45 9953.95 0
 

Similar threads